Neither side was able to find the net in 120 minutes of football, but Dortmund missed two penalties in the shootout to give Bayern victory in and provide Guardiola with a seventh and final title in Germany before he heads to Manchester City.
Guardiola, so often accused of being too emotionless during his time in Munich, broke down in tears as Bayern celebrated.
“Anything can happen in a penalty shootout, so we are delighted,” Guardiola told Sky after the game. “It has been an amazing three years at this club. I will miss the players so much.”
Bayern striker Thomas Mueller added: “It was an intense game. Penalties are always a horrific way to decide a game, but I think we deserved to win today.”
It was also an emotional evening for Mats Hummels, too. The Dortmund captain will move to Bayern this summer after eight years with Borussia.
Hummels' farewell ended early, as he fell victim to cramp and was replaced by Matthias Ginter in the 79th minute.
Bayern had the better chances in the first half. Thomas Mueller fired a speculative shot over the bar early on, before doing the same with a header 20 minutes later.
Both sides struggled to free themselves from a hard-fought midfield battle, however. Several Dortmund counter-attacks came to nothing, while Bayern searched in vain for the decisive final ball.
Only on the half hour mark did the game truly spark into life. Roman Buerki denied Douglas Costa with a smart save, before Pierre-Emerick Aubameyang fired wide as Dortmund hit back on the break.
Hummels, in the spotlight all evening, will have been grateful for a relatively uneventful first half in which the Munich outfit barely got into gear.
The Germany international almost got on the scoresheet just after the break, heading the ball over the bar from a Marco Reus free-kick.
Bayern hit back immediately, as Franck Ribery hit a loose ball across the face of goal on the half-volley.
Devilish crosses from Ribery and Costa followed as Bayern began to increase the pressure.
Hummels and his defensive colleagues were caught flat-footed on 64 minutes, allowing Mueller too much space to set up Robert Lewandowski, who scooped the ball over the bar.
With just 15 minutes to go, Ribery forced an instinctive save from Buerki, as Bayern began to pin Dortmund back in the final third.
Minutes later, Hummels was substituted off to muted applause from the Dortmund fans.
Bayern continued to push forward in vain, and two more Dortmund counter-attacks came to nothing in the final five minutes.
Neither side could break the deadlock, and Guardiola's farewell was taken to extra-time.
Ribery set up Lewandowski in the penalty area. The Polish striker was denied only by a brilliant challenge from Erik Durm.
Dortmund's best chance came in the 103rd minute, Henrikh Mkhitaryan firing a shot across the face of goal. David Alaba also had a chance for Bayern, but neither side could score, and the final went to penalties.
After Sven Bender and Sokratis failed to score for Dortmund, Douglas Costa fired home the winning penalty to give Guardiola the perfect happy ending.