Singapore: Nico Rosberg hung on for the narrowest Formula One victory for six years to win the Singapore Grand Prix on Sunday, celebrating his 200th career start in perfect style as he reclaimed the championship lead from his Mercedes teammate Lewis Hamilton.

Rosberg held on to beat a fast-finishing Daniel Ricciardo of Red Bull by just 0.488 of a second at the Marina Bay street circuit while Hamilton took third place, narrowly in front of Ferrari's Kimi Raikkonen.

Rosberg's third successive win, and first in Singapore, took him back to the top of the drivers' championship, eight points ahead of Hamilton with six races left.

Ricciardo, having pitted for fresh tires with 14 laps left, sliced Rosberg's lead from 25 seconds to under a second but ultimately fell just short of overtaking the German. It was the closest F1 finish since the 2010 race at this venue when Fernando Alonso edged Sebastian Vettel by three tenths of a second.

"Daniel tried to pull one up on me with the pitstop at the end, we knew it was going to be tight but we got there so I'm very happy," Rosberg said. "The whole car was on the edge, it always is here in Singapore, so it's very satisfying to finish like that."

His team boss Toto Wolff perhaps summed it up best.

"We nearly peed our pants at the end," Wolff said. "It was so close at the end, how it should be in Formula One; four really great cars, different strategies. I must take my hat off to Red Bull with their strategy by pitting him, we couldn't do that. Ricciardo was out of the blocks with amazing pace and it was really exciting at the end."

Ricciardo was only 5.2 seconds behind with five laps to go and it looked likely he would catch Rosberg, but as the ultrasoft tires passed their peak, he was not quite able to make up the ground.

"We tried something different with strategy and got to within half a second, it was close," Ricciardo said. "It was nice to be able to push to the last lap and put some pressure on him and give the crowd some hope."

Vettel finished a creditable fifth after having started at the back of the grid due to a technical malfunction in qualifying.

Red Bull's Max Verstappen started poorly from fourth on the grid and finished sixth, overtaking Alonso with seven laps to go. Force India's Sergio Perez held off Daniil Kvyat to finish eighth while Kevin Magnussen was tenth to give Renault only its second points finish of the season.

Rosberg got away well from pole position, beating Ricciardo in the race to the first corner.

The safety car came out almost immediately due to a spectacular accident in the middle of the pack just after the start. Force India's Nico Hulkenberg tried to get through a narrowing gap between the two Toro Rossos but clipped a tire on Carlos Sainz Jr.'s car and speared heavily into the pitlane wall.

After a couple of laps behind the safety car, the racing restarted at very short notice, almost catching out a safety marshall, who was picking up debris on the track when the field rounded the turn into the start-finish straight, and he was forced to sprint to safety.

The finishing order of the top four was already in place by the end of lap one, but that disguised a thrilling finish due to some risky pit strategies.

Hamilton, running fourth, came in for ultrasoft tires with 15 laps left, forcing Ferrari to hastily bring in third-placed Raikkonen the next lap, but they could not get the Finn back out quickly enough, and the move ultimately handed third to Hamilton.

Ricciardo had been gaining ground on Rosberg, with both on the hardest compound tire, with the gap down to three seconds with 15 laps left. The Australian looked capable of catching the leader, but the team gambled on bringing him for ultrasofts, expecting that would force Rosberg to do the same.

"You need a pretty big speed advantage to pull (a passing move) off here," Ricciardo said. "We did the right thing in the end. Staying on the same tire would not have given us any better chance.

"As soon as we did the pitstop, we thought Nico was going to come in so I pushed really hard on those tires, and in the end they were a little bit dead. At least it made it exciting."

Mercedes had intended to respond to Ricciardo's stop by bringing Rosberg in, but he was in the midst of backmarkers, and the team feared that a pitstop could bring him out behind Ricciardo, so they successfully gambled on keeping him out on worn tires and hoping he would hold on.