Lewis Hamilton claimed victory in the Bahrain Grand Prix after an engine problem hit runaway leader Charles Leclerc's Ferrari late in the race.

Leclerc had dominated after retaking the lead following a poor start and was on course for a maiden victory when his hybrid system failed.

Hamilton closed an eight-second deficit within three laps and swept by for his first win of 2019 with nine laps to go.

Leclerc would have slipped down to fourth behind Hamilton's team-mate Valtteri Bottas and Red Bull's Max Verstappen but was saved by a late race safety car.

As victory slipped from his fingers, the despair in Leclerc's voice was clear as he asked the team what had happened, and was told he had suffered a failure of the MGU-H, the part of the hybrid system that recovers energy from the turbo.

It cost him 40km/h on the straights and left him helpless as first Hamilton and then Bottas closed in at five seconds a lap.

"Oh my God," he said, as he saw a fairytale victory slip from his grasp on a weekend on which he had destroyed his four-time world champion team-mate Sebastian Vettel.

Vettel, meanwhile, made yet another high-profile error, spinning his car while being passed by Hamilton for what at the time was second place with 20 laps to go.

Vettel already needed a pit stop for fresh tyres, but he also suffered a front wing failure as he toured around to the pits, and the German finished fifth, two places behind his team-mate.

"That was extremely unfortunate for Charles," Hamilton said over the radio on his slowing down lap. "We have work to do to keep these guys on our tails."

It was a bitter blow for Leclerc, who thoroughly deserved the win, but the Monegasque had already done enough to announce himself as a major title contender.

He had started from pole position, but a poor start meant he dropped behind Vettel and Bottas on the first lap.

But he passed Bottas at the start of the second lap and then Vettel on lap four, around the outside of Turn Four, and proceeded to underline his superiority over Vettel by cruising off into a comfortable lead.

Until the Ferrari hit trouble in the closing laps, the race was all behind Leclerc, as Vettel and Hamilton swapped positions behind him.

Hamilton jumped Vettel at the first pit stops, but Mercedes's choice of soft tyres, while the Ferraris fitted mediums, left him struggling.

Vettel closed him down and passed for second on lap 24.

Hamilton felt he was in dire trouble, but he managed to keep Vettel in sight, so when both pitted for a final stint on mediums Hamilton was able to close on Vettel.

The world champion passed Vettel around the outside of Turn Four with 20 laps to go, and the German spun on the exit of the corner.

"Aargh," he said. "New tyres. Box."

It was another mistake that raised questions about Vettel's ability to race in high-pressure situations after a series of errors last year dashed his title hopes long before they should have died.

Vettel said he believed his front wing had failed because of the vibrations from his damaged tyres. Regardless, the dynamics within the Ferrari are now fascinating.

Vettel had started the season as their leader but Leclerc has now staked his claim and proved he will be a major force this season.