Bastian Schweinsteiger gave Bayern the lead, but Admir Mehmedi levelled before half-time.
Bayern wasted chances to grab a winner and they were punished by their former forward Petersen, who came on and scored within three minutes to earn a priceless victory for Freiburg and condemned Bayern to a third straight defeat in the Bundesliga.
Hertha Berlin remain level on points with Freiburg just outside of the drop zone after they failed to pull themselves clear and could only manage a goalless draw at home to Eintracht Frankfurt on Saturday.
There were few chances at the Olympiastadion on Hertha’s final home game of the season, and with Hannover and Freiburg both winning, it means they will have to wait one more week before being certain of their place in the Bundesliga next season. They travel to Hoffenheim next weekend still needing a point to be certain of staying up.
Hannover picked a timely moment to bag their first win of 2015, moving out of the bottom three with a 2-1 win at the Augsburg Arena which also dents Augsburg’s hopes of qualifying for Europe next season.
Lars Stindl scored both goals for the Lower Saxony side, who finished up with 10 men following a red card to Hiroki Sakai, playing against nine men. Paul Verhaegh, who had equalised for the hosts, was shown a second yellow card in the last minute with Raul Bobadilla joining him for an early bath in stoppage time.
Stuttgart climbed off the foot of the Bundesliga and gave themselves hope by and leap-frogging Hamburg with a 2-1 win over their relegation rivals at the Mercedes-Benz Arena.
Gojko Kacar gave Hamburg the lead, but Christian Gentner and Martin Harnik cancelled that out to earn the Swabians a thoroughly deserved win which, for the first time in months, took them out of the relegation zone.
Hamburg slipped into the bottom two, on the other hand, with the fate of both sides to be determined on the final day of the season.
Paderborn now prop up the standings after a last-gasp own goal from Uwe Hunemeier condemned them to a 1-0 defeat at Schalke.
The defeat leaves Paderborn three points adrift of automatic safety with one game to go – at home to third-bottom Stuttgart next weekend.
Mainz, meanwhile, ensured their place in the Bundesliga next season with a 2-0 win over Cologne, who guaranteed their safety a week ago.
Koo Ja-cheol and Jairo Samperio netted the goals for Markus Schmidt’s men as any lingering fears of relegation were dispelled.
At the other end of the table Raffael’s double sealed Borussia Monchengladbach’s place in the Champions League group stage next season with a 2-0 win at Werder Bremen.
Just above them Wolfsburg remain on course for the runners-up spot after they beat Borussia Dortmund 2-1 at the VW-Arena.
Daniel Caligiuri and Naldo scored quick goals at the start of the first and second halves with Pierre-Emerick Aubameyang’s strike in between too little for Dortmund.
Elsewhere, Bayer Leverkusen all but ended Hoffenheim’s hopes of qualifying for Europe next season with a 2-0 win at the BayArena courtesy of strikes from Hakan Calhanoglu and Stefan Kiessling.