Ba's sixth goal of the season in the 87th minute, after Andre Schuerrle's first-half opener, clinched a 2-0 victory that overturned a 3-1 loss from the first leg and sent Chelsea through on away goals.
Real Madrid and Chelsea nervously edged their way into the semi-finals of the Champions League on Tuesday, at the expense of Borussia Dortmund and Paris St Germain.
Real lost 2-0 in Dortmund, on a first-half brace from Marco Reus, but scraped through on a 3-2 aggregate thanks to winning the first leg 3-0.
Meanwhile in London, Chelsea beat PSG 2-0, with super sub Demba Ba scoring a dramatic winner just three minutes from time. Chelsea scraped through on the away goals rule on a 3-3 aggregate, having lost the first leg 3-1 in Paris.
“It was very much deserved that the team that tried to defend was punished. The team that played with their heart deserved to go through,” said Chelsea manager Jose Mourinho.
“I think we did enough at beginning of the second-half to score before we did. In the second-half it was pure ball possession. But it was difficult for us to penetrate ... The players knew what they had to do. Demba Ba made a crucial finish for us.”
Real went into the Dortmund showdown without world player Cristiano Ronaldo, left on the bench due to a strained tendon.
The whites made a bright start and were given a debateable penalty in the 16th minute for a handball by Dortmund’s Lucasz Piszczek.
However, Roman Weidenfeller did well to save the spot-kick from Andel di Maria.
Reus took advantage of a blunder by Real defender Pepe to give Dortmund the lead in the 24th minute, then 13 minutes later made it 2-0 after Robert Lewandowski hit the post with a low shot.
Dortmund were just one goal away from forcing extra-time but were unable to put away a third goal. The closest they came was when Henrikh Mkhitaryan hit the post after being set up by man-of-the-match Reus.
Real’s veteran goalkeeper Iker Casillas had to make a string of vital saves to keep Dortmund at bay in a frenetic finale. At the other end, Karim Benzema and Gareth Bale came close to scoring what would have been a decisive away goal for Real.
“We made mistakes and we deserved to suffer tonight,” said a relieved Casillas.
“When you are 2-0 down after half an hour you know it is going to be tough. We needed a lot of mental strength tonight ... We will not be able to commit so many mistakes in the semi-finals.”
It was the fourth consecutive season that the whites had reached the semis, taking revenge on the team that ousted them last season.
The other quarter-final second leg was even more heart-stopping, with Chelsea edging through by the skin of their teeth.
The Blues lost the in-form Eden Hazard to injury early on, but his replacement Andre Schurrle made it 1-0 in the 33rd minute, after David Luiz had headed on a throw-in.
PSG sorely missed injured striker Zlatan Ibrahimovic, and wasted several good chances to put the tie to bed. They paid for their profligacy in the 87th minute, when Ba cleverly turned in a shot from Cesar Azplicueta.
“It was a fantastic game. It was an unbelievable feeling. There was no pressure on us because PSG were through,” said Schurrle.
“We needed patience to wait for the final goal in the last three minutes. We hit the bar twice, but we never gave up. Jose Mourinho knew the situation. He gave a few speeches to us. He told us to be patient.”
It was a sad case of deja vu for PSG, who narrowly fell in the quarters last season against Barcelona.
“This is very hard for us to take,” said PSG striker Edinson Cavani.
“We should have finished them off with the chances we had. But we didn’t - and we are suffering now.” Wednesday will see Barca away to Atletico Madrid - after a 1-1 draw in the first leg - and defending champions Bayern Munich at home to Manchester United after battling out a 1-1 draw at Old Trafford.