Dogged defending by the reigning Greek champions left Bayern facing a frustrating draw until Martinez finally broke through with an hour gone at AEK, who travel to the Allianz Arena in a fortnight’s time.
“It was very difficult, the pitch was not good, we played well in the first half, but the final pass was missing,” said Arjen Robben.
“We started using our chances and once Javi got the first goal, you could feel the relief.
“This was an important win for us.”
The result leaves Bayern top of Group E and puts pressure on nearest rivals Ajax, who earned a 1-1 draw in Munich three weeks ago, to beat Benfica in Amsterdam later on Tuesday and join the Germans on seven points, while AEK remain bottom after three straight defeats.
Bayern have never lost a European game in Greece, but despite breaking a four-match winless streak with a 3-1 victory at Wolfsburg on Saturday in the Bundesliga, the German champions laboured until Martinez scored with an athletic half-volley.
The hosts’ best chance of the match came on 20 minutes when Argentinian striker Ezequiel Ponce held off Bayern defender Mats Hummels, but fired wide.
At the other end, Thiago Alcantara’s pass rolled agonisingly away from Bayern striker Lewandowski.
Just as it was looking like AEK might earn their first point in the group stage, Bayern turned the game.
Hummels picked out Robben, whose effort was blocked, but the ball flew towards Martinez, who slammed his shot home.
Any frustrations in the Bayern ranks disappeared and just two minutes later they struck again.
Serge Gnabry, a constant threat on the right wing, played in Rafinha inside the box with a clever backheel, and the Brazilian’s low cross found Lewandowski unmarked to tap home and delight the travelling fans.
It was Lewandowski’s third goal in two games after also netting twice at Wolfsburg.
Thiago tried an acrobatic volley of his own with 15 minutes left which flew wide as Bayern kept on the pressure to safeguard the three points.