Sebastian Vettel had to contend with a crazed track invader and two safety cars before claiming his third victory of the season at an incident-packed Singapore Grand Prix.

The Ferrari driver slashed the gap to Lewis Hamilton in the championship after the Briton suffered his first retirement of the year.

Red Bull's Daniel Ricciardo finished second with Ferrari's Kimi Raikkonen completing the podium places. Nico Rosberg, Hamilton's closest rival in his quest for back-to-back titles, crossed the line in fourth.

Vettel started from pole position after his qualifying masterclass on Saturday, and his win rarely looked in doubt.

Indeed it was the Vettel of old - the driver who sauntered to nine straight victories in 2013 and four consecutive championships while competing for Red Bull - who led every lap of a race which lasted over two hours.

For Hamilton it was his first retirement since last year's Belgian Grand Prix. The world champion bemoaned a lack of power shortly before the midway stage and was forced to park his car on lap 33.

It could have been worse for Hamilton, but with Mercedes bizarrely out of sorts at this testing street circuit, Rosberg could manage only fourth. With six races remaining he holds a 41-point lead over Rosberg with Vettel now just eight points further back.

Vettel burst out of the blocks and was three seconds clear of Ricciardo by the end of lap one. Raikkonen was next up with Daniil Kvyat in fourth and Hamilton and Rosberg running line astern in fifth and sixth.

With Vettel comfortable at the front, Formula One's only night race was turning into a rather processional affair. But that changed on lap 16 when the safety car was deployed after Nico Hulkenberg and Felipe Massa collided at turn one.

Hulkenberg, who will serve a three-place grid penalty at the next race as punishment for the incident, retired and Massa ultimately could not make it to the finish line either.

The safety car pitted three laps later and while the top three of Vettel, Ricciardo and Raikkonen were separated by only 1.5 seconds, Vettel appeared to have the race in control.

Indeed Hamilton, now up to fourth after Kvyat fell behind both Mercedes drivers at the first round of pit-stops, suggested Vettel was deliberately backing Ricciardo up into team-mate Raikkonen's clutches.

Then on lap 27 came a potentially pivotal moment in the title race.

Hamilton, who had been bidding to match Ayrton Senna's tally of 41 wins from 161 starts here, reported a sudden loss of engine power. He slid down the field, losing place after place.

The Briton desperately urged his Mercedes pit crew to resolve the problem, but a solution was not forthcoming. On lap 33, a space was cleared in the Mercedes garage and he retired.

"I was feeling super optimistic," Hamilton said. "I was on the prime tyres and the three cars in front were on the options but I was easily keeping up with them and thinking 'we have a race on our hands'.

"They were telling me to change all these things and then I was overtaken by two Manors so I knew l was last. When they started to pull away, I knew it was over."

Moments after Hamilton's retirement the safety car was back out for a second time, the 12th occasion in eight Singapore races, after a spectator had managed to enter the track.

"There is a fan on the track," shouted Vettel on the team radio. The man casually wandered alongside the speeding cars before voluntarily jumping back over the barrier. The incredible incident will call into question the security at this unique street circuit.

When the racing resumed, Jenson Button collided with the Lotus of Pastor Maldonado as the pair diced for 10th place.

"I should have known he was mental," the 2009 world champion said over the team radio after losing part of his front wing in the incident with the error-prone Lotus driver.

Button was later forced to retire and after Fernando Alonso parked his McLaren earlier in the race it meant the British team, who had been hopeful of a strong weekend, racked up yet another double retirement - their fourth of a dire campaign.

Elsewhere, Max Verstappen turned in a brilliant drive to fight back from last - after he stalled his Toro Rosso on the grid - to finish eighth.

Valtteri Bottas was fifth for Williams, Kvyat sixth, the Force India of Sergio Perez seventh ahead of Verstappen, with Carlos Sainz and the Sauber of Marcus Ericsson completing the points places.