Trailing 2-1 from the first leg of the semi-final in Germany, Joshua Kimmich put Bayern in front in just the third minute of the return fixture at the Santiago Bernabeu on Tuesday.
Karim Benzema ensured Bayern's lead lasted only eight minutes by heading in an equaliser.
Just 21 seconds after the interval, the French striker completed a turnaround as he tapped in to an empty net after Ulreich had slipped while coming to claim a backpass from Corentin Tolisso.
James Rodriguez restored parity against his parent club and put Bayern within a goal of the Kiev final on May 26, but Heynckes' men could not find a way through a shaky Madrid defence for a third time, losing 4-3 on aggregate.
An enthralling encounter served as Heynckes' final European game in charge of Bayern, the veteran coach having taken over for a fourth spell in October after Carlo Ancelotti's departure. He is set to be replaced by Eintracht Frankfurt boss Niko Kovac at the end of the season.
Speaking in his post-match media conference, Heynckes said: "Ulreich had a little blackout. We gave a world-class display, lots of beautiful football, it's such a shame we were eliminated.
"I've not seen Bayern play so well in quite a long time. All Madrid were doing was counter-attacks.
"Over both games, we were clearly the better team, but we've not been able to reach the final. We dominated, [Madrid goalkeeper Keylor] Navas was spectacular, especially at the end.
"This time it's permanent, I will never sit on a bench again. But I was not thinking of this last game as a pity, just a wonderful experience."
The Bayern boss also believed his side deserved more, having been the better side over two legs.
"If you see both games we were the better team. But unfortunately, we couldn't make the final. That is very disappointing for me and my players. Looking at today's game it was from both teams an advertisement for the game of football," Heynckes said.
"It was a great game, which we dictated. And Real can say thanks to [goalkeeper Keylor] Navas who had a great performance and at the end of the game denied us when we had very good chances."
"We shook ourselves and fought back and played well. You could see that Real were only playing counter-attacks in their own stadium," Heynckes continued. "I have to give my team a huge compliment. As I just told them: I haven't seen Bayern Munich this strong for a long time."