Raffael and Peter Niemeyer scored in the 49th and 81st minutes for promoted Hertha's first win at Dortmund since 2006, and only its second ever.
Robert Lewandowski pulled one back in the 88th, but was unable to prevent Dortmund's first home defeat in 19 games.
''We wanted to stay compact because we know how strong Dortmund are,'' Berlin coach Markus Babbel said. ''Of course there was also a bit of luck involved.''
''I'm very happy,'' Bayern coach Jupp Heynckes said. ''But we all know we need to improve further.''
In Saturday's late game, the 175th northern derby between Werder Bremen and Hamburger SV, Claudio Pizarro struck twice for a 2-0 win for Bremen.
Eight yellow cards were shown in a fractious game which left Hamburg rooted to the bottom of the table with one point from five games.
Pizarro finally scored in the 52nd, four minutes after he had a goal ruled out for an apparent foul on a defender.
Marko Marin swung a free kick against the post and Pizarro was first to react to head to the unguarded net.
The Peru striker made the game safe in the 78th, when he controlled a Marin corner on his chest before unleashing an unstoppable volley through a host of defenders.
Earlier, Hoffenheim won 4-0 at Mainz, Stuttgart beat Hannover 3-0 and Borussia Moenchengladbach also had a home win, 1-0 over Kaiserslautern.
Dortmund - which opens its Champions League campaign at home to Arsenal on Tuesday - was missing influential playmaker Mario Goetze following the 19-year-old's red card in the previous game against Bayer Leverkusen.
''Sometimes in such a game you need a knot-picker,'' said Dortmund coach Juergen Klopp.
Hertha made the better start and Torun Tunay should have scored when he dragged his shot to the right with only Roman Weidenfeller to beat in the 16th.
Shinji Kagawa did likewise at the other end two minutes later, before Mats Hummels headed a free kick straight at Hertha goalkeeper Thomas Kraft in the 27th.
Raffael scored at the second attempt when Weidenfeller saved his first effort only for the ball to bounce off the retreating Marcel Schmelzer, allowing the Brazilian to gratefully tuck away the rebound.
Raffael hit the crossbar in the 56th, before Dortmund substitute Lukasz Piszczek, Sven Bender and Kagawa all went close for the home side.
Bender then hit the crossbar in the 71st, but Hertha looked more likely to score from a counterattack, with Weidenfeller forced to save from Patrick Ebert in the 80th.
Niemeyer scored from the resultant corner when the goalkeeper could only parry Mijatovic's header. Niemeyer was there to bundle the ball over the line.
Lewandowski's late header ensured a hectic finish but Dortmund couldn't find an equalizer.
''Hertha are deserving winners. They defended with high discipline and we made it easy for them with our impatience. Still, there was a bit of luck about their goals,'' Klopp said.
Bayern left Arjen Robben in the stands as it put on a show of strength to move back to the top of the table before Wednesday's trip to Villareal in the Champions League.
Gomez opened the scoring in the eighth, when Toni Kroos found him unmarked for the simplest of finishes.
Ribery's delightful backheel - beyond the attentions of the retreating Maximilian Nicu and Pavel Krmas - deservedly made it 2-0 in the 26th, though TV replays showed the Frenchman was marginally offside when Thomas Mueller crossed after beating two defenders.
Ribery's next was even better in the 41st. The 28-year-old winger controlled Mueller's ball with a wonderful first touch, knocked it to the left beyond Nicu and ran past the defender, before slotting effortlessly across goal to the bottom right corner.
Ribery beat the offside trap to set up Gomez for his second in the 52nd, and Gomez completed the simplest of hat tricks in the 55th when the outstanding Ribery was involved again.
Freiburg defender Oliver Barth was first to the France winger's cross, but his attempted clearance rebounded off Gomez and looped over the helpless Oliver Baumann.
Garra Dembele brought down Mueller, and Gomez was ordered to retake his penalty in the 71st - after Bastian Schweinsteiger's slight infringement.
Gomez coolly slotted to right, having shot left for the first, to bring his tally to eight goals after five games.
In Moenchengladbach, Juan Arango's close range volley in the 58th proved the winner, when he was left unmarked for Tony Jantschke's cross.
Raul Bobadilla should have made it 2-0 in the 74th, when he shot with the outside of his foot to the left with only the goalkeeper to beat.
Goals from Stuttgart's Shinji Okazaki, Zdravko Kuzmanovic and Serdar Tasci ended Hannover's claim as the league's only unbeaten side.
Ryan Babel scored twice in Hoffenheim's win in Mainz. After Roberto Firmino opened the scoring, the Dutchman earned a penalty and converted it, before settling the issue with a fine individual effort in the 74th.
Mainz misery was compounded with Nikolce Noveski's own goal in the 85th.