With Malaga leading 2-1 in the dying stages, Dortmund's Marco Reus gave his side a glimmer of hope with a 91st-minute equaliser, but the Spaniards would still have gone through on away goals.
In the frantic closing seconds, Reus managed to stab the ball across the Malaga line for Brazilian centre-back Felipe Santana to poke in the crucial third Dortmund goal that put the Germans in the last four.
Television replays showed more than a suspicion both goals were offside, but Dortmundfans were too busy celebrating.
"We fought hard in the second half, it was my goal, but everyone worked for it, I'm proud of them all," beamed match-winner Santana.
Dortmund go through 3-2 on aggregate after last Wednesday's first leg finished goalless and are into the semi-finals for the first time since 1998.
Their coach Juergen Klopp admitted his side had ridden their luck.
"There is one very disappointed team in this moment and one lucky team," he told British Sky television.
"It's unbelievable. It was our worst game in the Champions League this season and not our best football.
"If we play like tonight we won't win the Champions League, but we have reached our target of the semi-final."
In contrast, Malaga were left devastated by the remarkable finish to the game.
"We were four minutes away from the semis," said Roque Santa Cruz. "There is huge disappointment in the dressing room. We had the tie in our hands."
Malaga winger Joaquin had given the Spaniards an early away goal before Poland striker Robert Lewandowski's equaliser made it 1-1 at the break.
Second-half substitute Eliseu then looked to have put Malaga in the semis in their debut season in Europe's top club competiton with a goal eight minutes from time, beforeDortmund produced two goals in two magical minutes.
It was heart-break for Manuel Pellegrini's side after the Malaga coach had to make a round-trip to his native Chile following the death of his father in the days before the game.
Dortmund continue their run as the only unbeaten team in the competition, but the winning goal came as late as the 93rd minute at the Signal Iduna Park.
Despite the hosts' bright start, a mistimed clearing header from Santana gave Malaga their first chance on 25 minutes, which the Spaniards pounced on to score the early away goal the Germans had dreaded.
When the ball fell to Joaquin, the former Spain winger pulled it back onto his left foot, out of reach of his marker Marcel Schmelzer, and rolled a shot through the legs of Neven Subotic and past goalkeeper Roman Weidenfeller.
It meant Dortmund had to score twice, but they needed only 15 minutes to draw level as Reus sublimely flicked on a pass between his own legs and into the path of striker Lewandowski.
Despite the attention of three defenders, the Poland star needed no further invitation to slot in his sixth goal in the competition.
Dortmund had a nervous final few seconds of the half as an unmarked Joaquin came close to netting a second for Malaga.
And Eliseu looked to have wrapped it up, 12 minutes after coming off the bench, when, from an offside position, he knocked Julio Baptista's rolling, goal-bound shot past Weidenfeller from close range to leave Dortmund reeling.
But with the hosts pushing forward frantically, Malaga right-back Jesus Gamez was tackled by Santana, and the loose ball fell to Reus, who stroked it in to give Dortmundhope.
And Santana was their 11th-hour hero when he stabbed the ball over the line in a desperate scramble after Reus's shot across goal.
Photos: Shah Rukh Khan, Rekha at a prestigious awards event
Oscars 2017: Emma Stone, Nicole Kidman, other stars on red carpet
Photos: Varun Dhawan, Alia Bhatt, Amitabh Bachchan walk the ramp
Photos: Priyanka Chopra at Oscars 2017 red carpet
Photos: Ranveer Singh, Ajay Devgn spotted at Mumbai airport