The fourth seed won a tough encounter on Centre Court 7-5 3-6 7-5 6-1, but the match did not finish until 11:02pm.
Tournament organisers had decreed play should end no later than 11pm and Murray faced the prospect of having to return on Monday to finish the match.
However, he managed to get the job done after starting the seventh game of the fourth set just seconds before the cut-off point.
Afterwards, the Scot admitted he thought play would be suspended before he could complete his victory.
'When I got up at 4-1, I asked and was told we had one more game. When I broke him I thought that was it,' he said.
Murray also faced another unusual problem - the spare ball kept on falling out of his pocket, leaving the umpire no choice but to award points to Baghdatis.
'It was annoying. I'm blaming the shorts - it wasn't my fault,' the Briton said.
He added: 'It was a tricky first week, and I'll need to play better. I was very nervous today. I had to hustle my way through the match.'
Murray won a tight first set 7-5 thanks to a break of serve in the 11th game, but the Cypriot hit back to take the second 6-3 before a 30-minute delay while the roof was shut.
With the 11pm cut-off in place, the players knew they had to get the match finished within 90 minutes or return on Monday.
Baghdatis started the third set strongly and marched into a 4-2 lead, but the Scot rediscovered his best form to break twice, including in the crucial 12th game, to take it 7-5.
Sensing that victory was close, Murray applied the pressure in the fourth set and quickly clinched it 6-1.
Murray will face 16th seed Marin Cilic in the fourth round, after the Croatian beat Sam Querrey 7-6 6-4 6-7 6-7 17-15 in what was the second-longest match in Wimbledon history at five hours and 31 minutes.
- Ghana Prodigy Atsu Named Rio Ave Player Of The Season 0 comment
- Sulley Muntari Doubtful For Novara Game 0 comment
- Bernard Bortey Haunted By May 9 Disaster 0 comment
- Ghana Federation President Backs Chelsea To Triumph Over Cotonsports 0 comment
- May 9 Remembered In Kumasi; Statue at Accra Sports Stadium 0 comment