Thomas Tuchel's Mainz have been a surprise package in the Bundesliga and enjoy a two-point lead after nine league games, but they suffered only their second defeat of the season at the hands of Aachen.
Goals either side of half-time by Aachen's Benjamin Auer and Marco Hoeger put the hosts 2-0 up before Hungary striker Adam Szalai pulled one back for Mainz on 68 minutes, but the visitors left themselves with too much to do.
Petric netted for Hamburg in the first-half to pull the scores back to 2-1 to Frankfurt after 23 minutes as the hosts took an early lead.
But in a bizarre spell, he headed into his own net on 65 minutes and then scored his third goal of the game just a minute later with another header, but this time for Hamburg.
Bayern conceded an early goal when Bremen striker Claudio Pizarro scored an early goal, but the visitors defence was later exposed when Schweinsteiger equalised as France defender Mickael Silvestre put him onside.
Werder dominated the second-half but Pizarro saw a header cleared off the line and Marko Arnautovic's freekick hit the post.
Schweinsteiger scored the winner with a superb shot on 75 minutes from 20 metres out to give Louis van Gaal's side a boost as they are 12 points adrift of Mainz.
The third round draw, the matches to be played on December 21 and 22, will be made this weekend.
Source: AFP Global Edition