Robert Lewandowski, James Rodriguez and Kingsley Coman scored in a one-sided first half, before James completed his hat trick and Canadian teen Alphonso Davies grabbed his first goal for Bayern in the second.
James became the first Colombian to score a hat trick in the Bundesliga. Bayern, the six-time defending champion, reclaimed the lead on goal difference from Dortmund, which had put the pressure on Saturday with a last-gasp 3-2 win at Hertha Berlin.
With eight rounds remaining, the April 6 clash between the two rivals could be a potential title-decider. Bayern was keen to impress after its midweek Champions League exit to Liverpool. "We wanted to play a good game for sure and we asked a lot of ourselves after Wednesday," Thomas Mueller said. "Today we dominated from the start."
Lewandowski scored with the outside of his boot in the third minute, James made it 2-0 in the 33rd after Leon Goretzka laid the ball off with his chest, and Coman, who earlier hit the post, let fly from the outside of the area in the 39th.
James grabbed another two goals within a four-minute spell early in the second half, before Davies, who came on with just over half an hour remaining, scored with a volley on the rebound after Mainz goalkeeper Florian Mueller denied Lewandowski.
BREMEN ON THE BREAK Max Kruse opened and finished the scoring for Werder Bremen to beat Bayer Leverkusen 3-1 away and boost its European qualification hopes on Sunday. The Bremen captain finished off a counterattack spearheaded by brothers Maximilian and Johannes Eggestein in the 14th minute and set up Milot Rashica to score on another breakaway in the 37th.
Leon Bailey pulled one back with a brilliant free kick in off the crossbar with 15 minutes of normal time remaining, but Kruse sealed Bremen's win with yet another counterattack in the fifth minute of injury time.
The win lifted Bremen to eighth, three points behind Leverkusen, which occupies the last place for Europa League qualification. Peter Bosz's Leverkusen put itself in contention with six wins from its last eight games.
Martin Hinteregger's first-half strike was enough for Eintracht Frankfurt to consolidate fifth place with a 1-0 win over last-placed Nuremberg. The visitors are now 20 games without a win.
More AP German soccer coverage: https://apnews.com/Bundesliga and https://twitter.com/AP_Sports