Cristiano Ronaldo put his side ahead in the 65th minute -- after leaving Manchester United by "mutual agreement" earlier in the week -- with a penalty which made him the first male player to score at five World Cups.
Ghana's Andre Ayew equalised in the 73rd minute, but Portugal responded with 78th-minute and 80th-minute efforts from Felix and Leao. A late effort from Osman Bukari made things interesting but Fernando Santos' side were able to ride out the storm.
Portugal had an early chance in the 10th minute when Ronaldo was sent through on goal by Bruno Fernandes, but Ghana goalkeeper Lawrence Ati-Zigi was able to smother the forward's poor first touch. The Portugal captain was denied again three minutes later as he rose highest for a header which he skewed wide.
Ronaldo had the ball in the net in the 31st minute after shrugging off the challenge of Alexander Djiku and slotting past Ati-Zigi, but the whistle had already been blown for a foul on the Ghana defender.
Ghana showed more attacking enterprise at the start of the second half, with Mohammed Kudus dragging a shot wide of Diogo Costa's left-hand post in the 55th minute as his side looked to spring a shock.
Ronaldo finally put his side ahead in the 65th minute with a cool effort from the penalty spot after being felled by Mohammed Salisu -- making World Cup history in the process.
- The VAR review: Why Ronaldo's penalty didn't get full review
But Ghana struck back in the 73rd minute, as Ayew turned home from close range after Kudus' low cross was deflected into his path -- sending the vocal Ghanaian support into delirium.
Their joy did not last for long, however, as Felix calmly finished past Ati-Zigi five minutes later to put Portugal back in front after Fernandes' pass split Ghana's defence.
Leao extended his side's lead moments later after side-footing home another Fernandes pass -- the AC Milan winger's first goal for Portugal.
Portugal looked to be strolling to victory, but Bukari's 89th-minute header meant there were late nerves for both sides.
Costa almost fluffed his lines after rolling the ball out to the lurking Inaki Williams in stoppage time, but the striker slipped at the crucial moment and Portugal survived.