Portugal defeated Ghana 2-1 in Brasilia on Thursday with World Player of the Year Cristiano Ronaldo grabbing the winner, but both sides exit the World Cup as the United States finish second in Group G on goal difference.

Germany top the group on seven points and the US are second on four.

Portugal, also on four, are left to rue their heavy opening loss to Germany, finishing third, while the Ghana squad riddled by infighting end last with just one point.

Portugal went in front on the half-hour when John Boye turned a cross into his own net and Ronaldo fired home an 80th minute winner after a goalkeeper error.

Ghana had levelled through Asamoah Gyan, who set a new African scoring record at the World Cup, but they could not convert pressure into a winning goal of their own and paid the penalty.

Portugal knew that their chance of progressing was slim as it required both a heavy victory for themselves and a favour from elsewhere. With Hugo Almeida and Helder Postiga injured it fell — as so often — to Ronaldo to inspire the attack in search of goals.

After a quiet World Cup to date, plagued with doubts over his fitness, Ronaldo produced an inspired first half as he tried to single-handedly drag his team to victory.

He forced Dauda into three saves before the break and also struck the bar with an audacious attempt from near the touchline.

Ronaldo was quiet in the second half, when Ghana were arguably the stronger team, but when Boye headed a cross high in the air and Fatau Dauda could only palm out weakly, he was perfectly placed to slam home the winning goal.

And Ronaldo could have had another to clinch things only to fire weakly at Dauda, turn over from point—blank range in injury time and then shoot at Dauda once more before the final whistle.

Ironically when the opening goal arrived in the 31st minute, Ronaldo was not involved. Referee Nawaf Shukralla was unfortunately positioned to block a Ghanaian attack and Portugal broke quickly to the other end.

Joao Moutinho showed wonderful ball-juggling skills to retain possession and after he fed Veloso to cross, Boye’s horrific attempt to clear sliced off his knee and flew in off the far post.

Before kick-off, Ghana seemed to have the better opportunity to reach the knock-out phase; they needed a much smaller goal swing to overtake the US, if they could beat Portugal.

But with harmony in their camp disrupted by a dispute over appearance fees and star players Sulley Muntari and Kevin-Prince Boateng being sent home for disciplinary reasons earlier in the day, their build-up was far from ideal.

In Asamoah Gyan, Ghana have a scoring hero to match Ronaldo but he made a quieter opening than the Portuguese star. Ronaldo had already threatened three times when Gyan collected a long ball over the top and fired off a shot the sprawling Beto did well to block.

After the break Gyan was better, leading his team as they sought the turnaround required to keep their World Cup dream alive. He had already hit the side netting with a shot when he crashed home a brilliant header from Kwadwo Asamoah’s cross to level.

Gyan then turned provider to give Majeed Waris the chance to put his side in front but his free header from the six-yard line was sent shamefully wide, and with it went Ghana’s hope of reaching the next round.

More In: FIFA 2014 | Football | Sport