Starved of supply all evening, Gomez feasted when Sami Khedira's delicious deflected cross found him five metres out, nodding it back across Rui Patrício. There were still 17 minutes remaining, enough time for Portugal, who had struck the bar through Pepe before the interval, to lay siege to the German goal. They almost broke through the barricades, too, when two minutes from time substitute Silvestre Varela found space at the far post – only Manuel Neuer's quick interventions kept it 1-0.

Caution had been the watchword in the early stages, with both teams content to sit back and invite the opposition to come forward and let their guards down. Not that it was all about soaking up the blows as one by one players had a jab, searching for a weakness. Fábio Coentrão almost found it when he drifted into a central position early on but, as he sought to punch the ball through to Hélder Postiga, Mats Hummels blocked well.

If that meant swift involvement in the game for the centre-back, Germany's other surprise starter Gomez, preferred to birthday boy Miroslav Klose, would have to wait rather longer after an opportunist early header. It was Lukas Podolski, playing on the left, who posed the biggest threat as he drew on his attacking wiles to twice lose his marker even if his finishing belied a man with 43 goals in 98 international appearances.

Germany were gaining the upper hand, but on the cusp of half-time Portugal almost conjured up an almighty sucker punch. Cristiano Ronaldo's corner from the left looked innocuous enough but the half-clearance fell straight to Pepe. The defender cushioned the ball beautifully, set himself and fired in a shot that hit the crossbar, bounced on the line and away to safety. The half-time whistle promptly blew and the players walked off to Madness's One Step Beyond – how Portugal wished Pepe's effort was.

Germany had 15 minutes to dust themselves off and they came out for the second round all guns blazing. It took desperate last-ditch blocks from Coentrão and Raul Meireles to deny them inside the first minute, but the game soon reverted to type. Neither midfield was able to really take the initiative, and though Khedira perhaps had most success, his slack pass almost cost Germany.

The ball was quickly fed to João Moutinho and he delivered a sumptuous pass into the path of Ronaldo. The Portugal skipper shaped to shoot but, from nowhere, the excellent Jérôme Boateng slid in with the timeliest of interventions. Ten minutes later Gomez turned near despair into triumph and Germany will go into Wednesday's meeting against the Netherlands with a quarter-final place almost in sight. Portugal have it all to do on their return here to face Denmark.