LONDON, England (CNN) -- Fernando Alonso had written off his chances of winning the Singapore Grand Prix on the grid -- two hours later he was celebrating an unlikely "lucky" victory.

Renault driver Fernando Alonso celebrates his first win for a year at the Singapore Grand Prix.

The two-time world champion had been competitive all weekend only to suffer a mechanical problem in qualifying that left him in 15th on a track where overtaking is difficult.

But after the safety car came out in the wake of his Renault team-mate Nelson Piquet's crash on lap 15, luck turned the Spaniard's way and he found himself in with a strong chance of victory.

"We were unlucky in qualifying and very lucky in the race," Alonso beamed after the 20th win of his career. "Obviously we started at the back and the first safety car helped me a lot.

"We were competitive straight away here. We were hoping to take the benefit of this good car here but after qualifying maybe our hopes were gone already as we [he and Piquet] started 15 and 16 and you know that it is nearly over.

"Without the safety car maybe I was finishing in the same position, 15 or 14. Again, today shows that Formula One is unpredictable on a Sunday.

"But a first podium of the season and first victory as well and I am extremely happy. I think I need a couple of days to realize we won a race this year."

Behind Alonso, Nico Rosberg delivered the best result of his three-season F1 career with second place for Williams.

And it could have been even better for the German, who fell foul of the harsh ruling, which meant he was given a 10-second stop-go penalty for having to take on fuel when the pitlane was closed under safety-car conditions.

Don't Miss

"When I saw the safety car coming out just on the lap where I had to pit, I was thinking 'this is not possible, it is every single time exactly the same thing,'" said Rosberg, who suffered a penalty for the same infringement in Canada last year.

"I was really annoyed and I thought that was it, that was the end of it. I then realized I was able to pull enough of a gap afterwards to be in a good position after my stop and go.

"I dropped to fourth and then they said to me that the guys in front still need to stop, so it was looking great again. It was me racing Fernando. I thought I might have a chance against him but he was just a bit too quick. It's still a great result for us."