BUDAPEST -- Lewis Hamilton took his first pole position since 2021 at the Hungarian Grand Prix and ended Formula One champion Max Verstappen's bid for a sixth straight pole on Saturday.

Hamilton pumped his left fist several times after placing just .003 seconds ahead of Verstappen on his last lap to secure a record-extending 104th pole but first since Saudi Arabia in December 2021.

"Get in there, let's go boys!" So good!" Hamilton shouted on team radio before letting out a high-pitch whoop.

"It's been a crazy year and a half ... I didn't think today we'd be fighting for pole," Hamilton said. "I just need to try and see if I can sleep tonight."

It might not be easy, given the rush of joy he felt.

"I just had a grin on my face, what an uplifting feeling for the whole team," the seven-time F1 champion said. "When I went into the last run I gave it absolutely everything."

Wins and poles used to be as common for Hamilton as they are becoming for Verstappen, but Hamilton feels Mercedes is finally giving him a better shot at a first victory since his record 103rd race win, also in Saudi Arabia two years ago.

"I always have that belief. I guess it was just a question of how long that would be," the 38-year-old British driver said. "Last year I had no confidence in the car. Now there's no fear that it's going to throw you into the wall."

McLaren driver Lando Norris qualified third behind Verstappen at the Hungaroring, the track where Hamilton won his first race for Mercedes in 2013.

Norris is well placed to push for a second straight podium after finishing second at the British GP.

"I feel excited. Race pace was as strong as Silverstone," Norris said. "With cars up there tomorrow, hopefully we can use them."

His teammate Oscar Piastri, who finished fourth at Silverstone, maintained his form when he qualified fourth ahead of Alfa Romeo's Zhou Guanyu and Ferrari's Charles Leclerc.

Valtteri Bottas qualified seventh for Alfa Romeo, ahead of Fernando Alonso (Aston Martin), Sergio Perez (Red Bull) and Nico Hulkenberg (Haas).

Perez finally ended a terrible run.

Since taking the Miami GP pole in May, the Mexican driver has failed to qualify in the top 10 -- qualifying 16th, 11th, 12th, 15th and 15th. His struggles continued when he crashed just three minutes into the first practice session on Friday.

Verstappen, meanwhile, complained he felt like he was "driving on ice" in qualifying due to a lack of balance.

"We should be ahead with the car we have, but so far this weekend we haven't been on it," he said.

But qualifying second will hardly faze the Dutchman, considering he won from 10th place on the grid last year.

He is cruising toward a third straight F1 title. He has won the past six races and eight in a campaign where he already leads Perez by 99 points, so Hamilton knows the task facing him.

"We'll bring our A game as a team," he said. "It's going to be difficult to fight these guys tomorrow."

Hamilton's teammate, George Russell, took the pole here last year but was among the five drivers eliminated from the first part of qualifying after getting stuck in traffic, prompting team principal Toto Wolff to bang his fist on the table and Russell to let fly with an expletive.

Ferrari's Carlos Sainz Jr. starts a lowly 11th while Daniel Ricciardo qualified 13th on his unexpected return to F1 with the AlphaTauri team. American Logan Sargeant was last for Williams.

Ricciardo was released by McLaren last year but the Australian veteran was given an AlphaTauri seat after Nyck de Vries was cut last week by team principal Franz Tost after failing to score a point in 10 races.

"It was a very difficult and also emotional decision," Tost said. "Unfortunately this didn't work as expected, and therefore we decided then to take Daniel."

Earlier Saturday, Hamilton led the final practice ahead of Verstappen and Perez.

Rampaging Red Bull will take some stopping.

The team has won every race, with Perez getting the other two, and 11 in a row including the final race of 2022 to match the record for consecutive wins set by McLaren in 1988.

The good news for Hamilton was securing pole at the Hungaroring was often decisive on the sinewy 4.4-kilometre (2.7-mile) track, which is one of the most difficult to overtake on and is known as "Monaco without walls."