The Brit, who was unlucky to suffer a tyre blowout while leading his home race at Silverstone last week, claimed his third pole position of the season and his 29th of his career.
“We were miles off this morning, we made a change and I didn’t know if it would work but it did,” Hamilton said.
His lap denied three-time world champion Sebastian Vettel pole at the Red Bull driver’s home race – but the German remains confident he can win.
Vettel has yet to win a German Grand Prix and this weekend is his sixth attempt at the feat – it is only one of three races on the current calendar the championship leader is yet to win.
“It was quite close,” said Vettel. “I tried everything I could but unfortunately it wasn’t enough.
“We are much closer to them here than in Silverstone so we are quite confident for tomorrow.”
Fellow German Nico Rosberg, who won the controversial British Grand Prix said that his failure to reach Q3 was unbelievable.
“It was quite a shock really,” Rosberg said. “I didn’t see it coming. The team didn’t expect the track to ramp up that much. It really is a big disappointment. Unbelievable. We just didn’t judge it correctly.”
Mercedes team principal Ross Brawn admitted that the team had let Rosberg down, but remained optimistic.
He said: “We had a cut-off time that we thought would be reasonably comfortable but the track simply got a lot quicker at the end and we hadn’t anticipated it. He didn’t have the greatest of laps anyway so that was adding to the frustration.
“But we didn’t make the right call on that one, but we will have to see what benefit it brings in the race because Nico now has free tyre choice.”