Ferrari’s Sebastian Vettel was runner-up, ending Mercedes’s run of five successive one-two finishes, with Hamilton’s teammate Valtteri Bottas third.
Max Verstappen crossed the finish line second for Red Bull but dropped to fourth due to a five-second penalty imposed for an earlier unsafe release and collision with Bottas in the pit lane.
“That was definitely the hardest race I’ve had but nonetheless I really was fighting with the spirit of Niki,” said Hamilton, who dived into the trackside swimming pool after the podium formalities.
“I know he will be looking down and taking his hat off. I was trying to stay focused and make him proud,” he added of the Austrian, the triple world champion and Mercedes team’s non-executive chairman, who died on Monday aged 70.
The five-times world champion, now leading Bottas by 17 points, and Verstappen finished under investigation after they banged wheels into the chicane following the tunnel exit two laps from the end.
The Briton, whose medium tyres were so worn by that point that he questioned the team’s strategy, was forced to cut the corner.
“I don’t know what you’re thinking by keeping these tyres on man. You need to hope for a miracle,” he had said earlier, keeping Verstappen - on longer-lasting harder tyres - behind him for lap after lap.
The miracle, with Hamilton wearing a red helmet with Lauda’s name and colours while the car carried a variety of tributes, duly happened as if by the late champion’s celestial command.
“That was an incredible drive. There was no one else who could have done that,” Mercedes chief strategist James Vowles told him over the radio after he crossed the line.
Ferrari’s Charles Leclerc had created much of the early excitement of an entertaining race but was also the sole retirement, stepping out of the car in the pits with just 19 laps gone.
The Monegasque, starting 16th, was up to 12th by the end of lap seven after overtaking McLaren’s Lando Norris and Haas’s Romain Grosjean at the hairpin and Rascasse.
The youngster, who had vowed to be aggressive after a Ferrari’s strategy blunder messed up his qualifying, then paid the price when he tried the same move on Renault’s Nico Hulkenberg at Rascasse.
Leclerc spun and picked up a right rear puncture, limping home to the pits on a rim and flailing rubber, losing a lap to the leaders and flinging out debris that led to a safety car period for marshals to sweep the track.
Red Bull’s Pierre Gasly finished fifth, with Carlos Saiunz sixth for McLaren followed by Toro Rosso pairing Daniil Kvyat and Alexander Albon.
Renault’s Daniel Ricciardo, last year’s winner for Red Bull, was ninth and Romain Grosjean collected the final point for Haas.