Bayern appeared to be cruising to victory at 2-0 up but, when they conceded a penalty, they looked at risk of caving in until their 40million euro man came on to the field for only his second appearance for the club.
"Above all, it was the introduction of Javi Martinez which led to us playing with more control again," said Heynckes.
"He played very well going forwards and very intelligently. And then he created the third goal sensationally."
Bayern were perhaps thinking ahead to Wednesday's Champions League tie with Valencia when they appeared to sit back after going two goals up inside the first 13 minutes.
"Conceding the goal was unnecessary," said captain Philipp Lahm.
"There was a phase in which we just lost control of the game a little, but otherwise we can be very happy.
"The first half was very, very good - we should have made it 3-0 earlier on."
Mainz arrived in Munich with a good record against Bayern with a win and a draw on their last two visits to the Allianz Arena, but the early goals saw their gameplan go out of the window.
"We were behind incredibly quickly, and unfortunately, and that was pretty much game over," said their coach Thomas Tuchel.
"We showed a bit more courage after half time. On the one hand I am angry, but on the other hand it is the most normal result when Mainz play Bayern."