Red Bull's Sebastian Vettel edged out Lewis Hamilton's McLaren to take his eighth pole position of the season at the Hungarian Grand Prix.
Red Bull broke a curfew on working overnight to overhaul Vettel's car and the changes helped him get back on top.
McLaren's Jenson Button lines up third ahead of Ferrari's Felipe Massa, who out-qualified Fernando Alonso for the first time in 2011.
Last year's winner in Hungary, Mark Webber, starts in sixth for Red Bull.
The main protagonists had been split by just half a second on Friday and it was another close battle in qualifying as Vettel edged out Hamilton by just 0.163 seconds.
"Any one of five drivers could have taken pole position," BBC F1 analyst Eddie Jordan said. "We were served up another titantic battle. Vettel has answered all the critics - he has unbelievable one-lap pace."
A decision by Red Bull on Friday to break with Vettel's car the six-hour overnight curfew, which was introduced by the sport's governing body this year to stop teams working round-the-clock on their cars, seemed to be the key to his improved performance.