The German side's run in the competition appeared to be as good as over after Eliseu's strike in the 82nd minute made it 2-1 to Malaga and left the host needing two goals to progress after last week's first leg ended goalless.
Marco Reus breathed life into Jurgen Klopp's side with a close-range finish in the first minute of stoppage-time but there was even greater drama to come as Dortmund pressed on in search of a third goal, which duly arrived with seconds remaining as Felipe Santana scrambled home.
Joaquin's 25th-minute opener for Manuel Pellegrini's visitor was cancelled out by Robert Lewandowski's superbly-crafted goal five minutes before the break, but that was mere prelude to the drama - and acrimony - that was to come after the break.
Both Eliseu's strike for Malaga and Santana's third for Dortmund should both have been ruled out for offside, as the officiating team led by Scotland's Craig Thomson ensured this memorable contest would also be tainted by controversy.
Dortmund's players and fans will probably not lose too much sleep over the shortcomings of the officials, with the frenzied delight of the home contingent starkly contrasted by Malaga's crestfallen players, who as the final whistle blew clearly were struggling to comprehend how they had been turned over.
A nervy opening was perhaps understandable with so much riding on the result, and it took until the 16th minute for the first effort on goal to arrive as Lewandowski sent a chipped effort sailing over the bar.
After failing to produce a shot on target in the first quarter of the match, Malaga went ahead courtesy of its first meaningful attack.
Julio Baptista started the move with a pass into Joaquin, who exchanged passes with Isco before selling his marker a dummy and sending a low finish into the left corner.
Reus saw a shot charged down in the 37th minute as Dortmund searched for a way back, but the home fans did not have much longer to wait for the breakthrough as the host conjured a goal of real class five minutes before the break.
Mario Gotze's incisive forward pass was backheeled beyond the Malaga backline by Reus into the path of Lewandowski, who expertly dinked the ball over the sprawling Willy Caballero before tucking the ball home under pressure from Jesus Gamez.
The second half began with a bang with both sides going close to adding to the scoring inside three minutes.
First Lewandowski was afforded time to take aim from the edge of the area but Caballero got down to save, while two minutes later Roman Weidenfeller produced a fine reflex stop to deflect away Joaquin's downward header.
The host was given a let-off when Marcel Schmelzer appeared to raise his hands to the face of Gamez amid a tussle by the touchline, but rather inexplicably it was the Malaga man who went into the referee's book.
The home fans were on their feet in the 75th minute ready to acclaim a goal as the unmarked Reus looked to turn home a low centre from six yards but Caballero's trailing leg was in the right place as the Malaga number one made a wonderful save.
Caballero was again the hero for the visitor in the 79th minute as Gotze was played clean through but the goalkeeper flicked out a leg to deflect the ball inches wide of the post.
Caballero's heroics looked set to be the cornerstone of a famous win when three minute later Malaga went 2-1 up as Baptista's goalbound shot was turned home by Eliseu from almost on the goal line, despite the substitute having strayed offside.
The match appeared to be destined to end in Malaga's favour as added time arrived, but all that changed when Dortmund was awarded a free-kick 40 yards from goal.
Caballero was helpless to deny Dortmund yet again as woeful defending from the set-piece saw the ball break to Reus to fire in from close range.
The host still needed a goal to progress to the last four, and incredibly it arrived in the third minute of added time.
The officials failed to spot three Dortmund players in offside positions when the ball was launched into the area, but when the ball broke to Santana - also in an offside position on the goal line - he had no hesitation in blasting home to trigger scenes of disbelieving delight in the Westfalenstadion.