MONTMELO, Spain (AP) — Lewis Hamilton took pole position ahead of Sebastian Vettel at the Spanish Grand Prix, restoring Mercedes' dominance in Formula One qualifying on Saturday.

Hamilton gave Mercedes its 19th pole in 20 races, two weeks after F1 leader Vettel broke its run at the Russian GP in a one-two with Ferrari teammate Kimi Raikkonen.

Here, Vettel was 0.051 behind.

It was Hamilton's 64th career pole and his third in five races this year, putting the three-time world champion in position to challenge Vettel for the series lead on Sunday. With two wins in four races, Vettel has a 13-point advantage over Hamilton.

"It is going to be a tough race for us, when you see how close it is between us — it is milliseconds," Hamilton said. "It is a long run down the first turn, so it is important to get a good start."

Mercedes' Valtteri Bottas, who won the race in Russia, was third, followed by Raikkonen, setting the stage for another duel between the front-running teams.

Max Verstappen, the 2016 winner at a record age of 18, and fellow Red Bull driver Daniel Ricciardo will start the race from fifth and sixth on the grid.

McLaren's Fernando Alonso bounced back from Friday's breakdown during practice, making the third session of qualifying for the first time this year and finishing a season-best seventh, ahead of Sergio Perez of Force India and Felipe Massa in his Williams.

It was a busy morning in the garages of both Mercedes and Ferrari, which had to replace engines.

Bottas missed all but eight minutes of the third and final practice session earlier when two separate mechanical problems led to his team needing to replace his engine with the one used through the first four races.

"For me, starting the day with the engine change and moving back to the old engine, I was always going to be on the back foot," Bottas said. "It wasn't one of my best qualifying sessions but I'm happy with the job that the team has done."

Ferrari also had to change the power unit of Vettel's car following his precautionary stop in pit lane near the end of the third practice because of a "telemetry issue."

With the new engine in place, Vettel's car gave him a scare when he slowed down just two laps into qualifying, and his team ordered him to return to the garage. But the problem solved itself and Vettel continued on the track.

"It wasn't the ideal end, but considering the morning we had, it was a really good recovery," Vettel said about his second-best time. "Yesterday, I wasn't feeling the rhythm. Today it was better. In terms of performance, it will be really close."

Hamilton won at the Circuit de Barcelona-Catalunya in 2014, as did Vettel in 2011, two of 10 different winners in as many years at the race often used by teams to bring major upgrades to their cars.

So far, it looks like tweaks made by the title contenders have canceled one other out.

Hamilton and Vettel both pointed to the unpredictable gusts of wind — in otherwise ideal sunny conditions — that have troubled drivers all weekend.

Hamilton described how the same turn can be completely different to handle, depending on the wind.

"It's very gusty here. From corner to corner, sometimes you break in the same spot, but you tail off because of a tailwind. It was tricky for us," Hamilton said.

Vettel is also aware of the problem, saying "with the wind, you never know what to expect."