(CNN) -- Germany's Sebastian Vettel claimed pole position for his home grand prix at Hockenheim with a storming final lap in qualifying on Saturday.
The Red Bull driver recorded a time of one minute 13.791 seconds to edge out Ferrari's Fernando Alonso by two thousandths of a second.
Alonso's teammate Felipe Massa was third fastest, edging out Mark Webber in the second Red Bull.
"It will be interesting to work out how much distance two thousandths of a second is!
"All session Fernando was very strong and Ferrari are generally very competitive," Vettel told AFP.
"My last run wasn't 100 per cent perfect, I had a bit here or there where I went above the limit but in the end it was enough by nearly nothing to stay ahead and get on pole," he added.
Spain's two-time world champion Alonso had dominated the first two sessions of qualifying and looked set to claim pole after laying down a blistering early time in the final session for the top 10 qualifiers.
But Vettel edged him before Alonso came up short with his final run, leaving Ferrari stil without a pole since the 2008 Brazilian Grand Prix.
Webber had the chance to make it another Red Bull one-two on the grid but an error on his final run cost him valuable time.
Reigning world champion Jenson Buttton outqualified his McLaren teammate and title leader Lewis Hamilton as they claimed fifth and sixth on the grid.
But there was another qualifying disappointment for seven-time world champion Michael Schumacher, who could only set the 11th fastest time in his Mercedes.
A big majority of the crowd had come to see their native son in his comeback season, but fellow German Nico Hulkenberg in the Williams pipped him to a place in the final session.
Schumacher was again slower than his compatriot and teammate Nico Rosberg, who eventually claimed ninth place on the grid.
He said they had both wanted to put up a stronger display in front of a patriotic home crowd.
"There isn't much more to say about qualifying other than the result was what was achievable for us today," he told AFP.
"We clearly wanted to achieve more for our fans and it was disappointing because we had expected to be able to fight for fifth or sixth place."
Robert Kubica was seventh best for Renault with Brazilian veteran Rubens Barrichello in eighth for the improving Williams.