BUDAPEST, Hungary — Four-time Formula One champion Sebastian Vettel gave struggling Ferrari a boost with the fastest time in a rain-soaked second practice for the Hungarian Grand Prix on Friday.

He was .272 seconds ahead of Mercedes driver Valtteri Bottas and 1.32 clear of McLaren's Carlos Sainz Jr. as it rained throughout the afternoon on the Hungaroring track.

Ferrari needs to bounce back from a demoralizing Styrian GP in Austria last week, when Vettel and Charles Leclerc crashed into each other on the first lap and went out.

Defending F1 champion Lewis Hamilton, who was fastest in the first practice for Mercedes, was one of seven drivers not to post a time in Friday afternoon's second session.

“This is such a great track to drive in the dry, but it’s very tricky in the wet,” said Hamilton, who is looking to win the race for the eighth time to equal Michael Schumacher's single-track record at the French GP.

Given how difficult overtaking is on the sinewy and winding Hungarian circuit, gaining good grid position is crucial. There is a third and final practice at Saturday lunchtime ahead of qualifying in the afternoon.

“Looking ahead to qualifying, I think it is going to be a lot closer as it’s not such a power-dependent circuit," said Hamilton, who is gunning for a record-extending 90th pole position in F1. "I’m hoping for a tighter pack.”

Lance Stroll was fourth fastest and his Racing Point teammate Sergio Pérez, who slid off the wet circuit at one point, was fifth. Racing Point uses Mercedes engines and has shown good speed this season.

Earlier Friday, Hamilton was .086 seconds quicker than Bottas and .527 seconds ahead of Pérez.

That performance was even more impressive considering he was using a slower hard tire compound. Pérez, meanwhile, went off track briefly after his right front tire started to shred.

Ferrari was off the pace in the morning, with Vettel and his teammate Charles Leclerc both more than one second behind Hamilton's leading time.

Red Bull driver Max Verstappen, who was eighth quickest behind the two Ferraris, made an angry hand gesture and ranted at Williams driver Nicholas Latifi after being blocked by him.

“(First practice) was not what we wanted and we have a lot to look into," Verstappen said. “It’s a shame that it was raining this afternoon because we already had a few things to change and we could have had a good comparison to work from.”

The Mercedes drivers have won one race each from pole position this season. Bottas won the season-opening Austrian GP and Hamilton clinched the Styrian GP in Austria last Sunday for his 85th F1 win.

“There are strong areas to our car but we still have work to do to match Mercedes,” Verstappen said. "The weather looks like it could be (the same) for the rest of the weekend, and we don’t know how much rain will come.”

But given how well Hamilton drives in wet conditions, that is hardly going to be an advantage for his rivals.

___

More AP auto racing: https://apnews.com/apf-AutoRacing and https://twitter.com/AP_Sports