Gomez was moments away from being substituted, with Miroslav Klose already waiting on the touchline, when he rose to knock in a deflected cross from Sami Khedira in the 72nd minute.
After victories both in the quarter-finals of Euro 2008 and the third-place play-off at the 2006 World Cup, this was the German's third straight win over Portugal in major tournaments to give Germany a winning start in Group B.
Portugal captain and Real Madrid star Cristiano Ronaldo had a subdued night by his own lofty standards and he rarely got the better of his marker Jerome Boateng.
Real Madrid star Pepe came perilously close to putting Portugal ahead a minute before the break when his strike beat Manuel Neuer, but the ball deflected down off the crossbar onto the goal-line to bounce away from danger.