Portugal entered the match with a far inferior goal difference and needed a big win over Ghana to have a chance at reaching the next round.
John Boye's own goal handed Portugal the lead, but the African side equalized in the 57th minute through Asamoah Gyan, giving the Black Stars a chance at going through.
With the United States losing 1-0 to Germany in the other Group G match, another goal for Ghana would have been enough. However, some poor goalkeeping from Fatau Dauda handed Ronaldo the winning goal.
The result moves Portugal level on four points with the United States, but the Americans go through on goal difference, while Ghana finishes on the bottom of the group with just one point.
Prior to the match, two of Ghana's better players, midfielders Kevin-Prince Boateng and Sulley Muntari, were sent home after separate incidents involving Ghana officials.
And the match didn't start well for the African nation as an attempted cross from Ronaldo sailed over the head of Dauda and struck the crossbar.
Ronaldo threatened again with a close-range header in the 19th minute that Dauda was able to parry, but Miguel Veloso's left-wing cross was turned into his own net by Boye in the 31st, putting Portugal in front.
Ghana was handed a lifeline in the 57th minute when a cross from Kwadwo Asamoah found Gyan at the back post for a free header that he powered home.
Majeed Waris then spurned a great chance to put Ghana in front when he headed a shot wide of the net from six yards with goalkeeper Beto at his mercy.
The difference came in the final 10 minutes as a deflected cross was poorly cleared by Dauda on his goal line, handing Ronaldo an easy rebound goal that still wasn't enough for Portugal to advance.