McLaren driver Sainz chased Gasly relentlessly over the second half of the race at Monza, which was red-flagged when Charles Leclerc crashed heavily at the Parabolica, but he could not find a way to finish higher than second ahead of Lance Stroll.
Hamilton dominated the early stages, but a penalty for pitting when the pitlane was closed dropped him to last and left him having to charge back to seventh.
At the start, Valtteri Bottas appeared to react slower than Hamilton on the front row and he was quickly passed by Sainz on the run down to Turn 1, where the Finn was then put under pressure from Lando Norris.
The Mercedes and the McLaren touched at the apex of Turn 2 and their battle continued through Curva Grande, with Norris then ambushing Bottas around the outside of the della Roggia chicane.
They made more contact – wheel to wheel – as Norris barged by, with Bottas then falling behind Sergio Perez and Daniel Ricciardo as he struggled to get up to speed on the run to Ascari, suspecting he had picked up a puncture, which Mercedes then assured him was not the case.
Up front, Hamilton smoothly surged clear of Sainz, 1.3 seconds clear by the end of the first lap of 53.
The world champion set about extending that lead throughout the first stint, with Sainz quickly gapping his teammate, who was soon being harassed by Perez.
Hamilton continued extending his lead over the next 18 laps, which reached 12.5s by the time the race was turned on its head when Kevin Magnussen ground to a halt approaching the pitlane and the safety car was deployed.
Magnussen's stricken Haas had to be pushed into the pitlane by the marshals, which meant the pitlane was closed – 11-seconds after the safety car was called – but Hamilton headed in to switch to the medium tyres.
The rest stayed out, apart from Alfa Romeo's Antonio Giovinazzi, who was placed under investigation alongside the leader, with Mercedes telling Hamilton it expected him to get a penalty.
That sanction did come, but only after the race was suspended after Leclerc's massive accident at the exit of the Parabolica.
The pack had come in once Magnussen's car was finally out of harm's way and the pitlane was re-opened, which boosted the few cars that had stopped just before the safety car – including Gasly, Kimi Raikkonen and Leclerc, and Stroll, who did not come during the initial disruption.
At the end of the first lap after the restart – the 24th tour – Leclerc lost the rear of his Ferrari as he accelerated out of the famous long right-hander and as he corrected the slide his car snapped left and he shot into the barriers at high speed.
Leclerc was able to climb from his car and went to the medical centre for precautionary checks before being released, with the race stopped for over 25 minutes as the barrier was repaired, with the leading order Hamilton, Stroll, Gasly, Raikkonen, Giovinazzi, Sainz and Norris.
During this delay, Hamilton was handed the same 10s stop/go penalty that had been given to Giovinazzi just before the red flag, and he climbed from his car to speak with his engineer at the head of the queue, then scooted down to speak to the Mercedes strategists and senior leadership before visiting the race control area of the main Monza pit building.
When the race got underway via a second start at the beginning of lap 28, Stroll made a slow getaway, which meant Gasly could surge ahead of the Racing Point and chase Hamilton, who pitted to serve his penalty at the end of the second 'first' lap.
That left Gasly running clear of Raikkonen, as Giovinazzi then dropped out of the lead fight as he served his penalty, with Sainz passing Stroll – who had cut the second chicane after locking up on the first lap of the restart to drop behind both Alfas – into Turn 1 on lap 29.
Gasly was then tasked with building a lead, while Sainz chased and then attacked Raikkonen into the first chicane on lap 34, muscling his way by at the apex of Turn 2 and setting off after the AlphaTauri.
At the start of lap 35, Gasly lead Sainz by 4.1s, with the two leaders initially lapping closely in the low 1m24s.
Sainz was briefly able to get into the 1m23s as he chased the leader, who looked calm in lead even as his lead was slowly erased over the remaining 18 laps.
The McLaren driver consistently cut Gasly's lead but was stymied by the dirty air coming off the AlphaTauri and he struggled to get into DRS range.
He eventually managed it, but only on the final tour – with Gasly weaving to try and break the tow where he could – and Sainz was never able to run close enough to make a move for the lead. Gasly therefore held on to win by 0.4s, with Stroll third, 3.3s adrift.
Norris took fourth as Raikkonen fell to 13th on the softs, with the rest of the frontrunners all on the mediums, ahead of Bottas, who struggled to make any progress in traffic all afternoon.
Ricciardo was sixth, with his Renault teammate Esteban Ocon, the second AlphaTauri of Daniil Kvyat and Perez rounding out the top 10.
The last three points scorers were overhauled by Hamilton, charging on the hards, as he recovered from P17 and last to finish seventh.
He was nearly 30s off the lead when he served his penalty and, after a string of fastest laps, he cut his way into the points with a series of passes, eventually coming home 17.2s behind Gasly.
Alex Albon, who clashed with Gasly at the initial 'first corner' in an incident that was not investigated, came home 15th, while his teammate Max Verstappen retired shortly after the second start when Honda spotted a possible power unit issue.
Ferrari's home race had got off to a bad start before Leclerc's crash when Sebastian Vettel suffered a brake failure at Turn 1 early on, and he retired in the pits after smashing through the first chicane's runoff marker boards.
|2||Carlos Sainz Jr.||McLaren||0.415|
|3||Lance Stroll||Racing Point||3.358|
|10||Sergio Perez||Racing Point||23.224|
|13||Kimi Raikkonen||Alfa Romeo||36.312|
|15||Alex Albon||Red Bull||37.533|
|16||Antonio Giovinazzi||Alfa Romeo||55.199|
|Max Verstappen||Red Bull|