Hamilton, buoyant after winning the last two races on the F1 calendar to close to within nine points of title leader Rosberg, cut a dejected figure after his blunder in the final session of qualifying.
"The car was good. It was me. I just wasn't on it," said Hamilton, who had dominated the earlier practice sessions.
"If Nico gets a good start tomorrow he'll be gone," he told the official F1 website.
Rosberg also clipped the wall on his fastest lap on his way to a time of one minute 42.754 seconds but rode his luck to take top place on the grid for the 25th time.
Hamilton, who preceded him with his run, hit it harder, shredding his front right tire with the session red-flagged while marshals cleared the debris.
There were other surprises on the tricky new circuit in the Azerbaijan capital with Sergio Perez second fastest for Force India, unfortunately only good for seventh on the grid after picking up a five-place penalty for a gearbox change.
It has left Daniel Ricciardo of Red Bull on the front row with Rosberg.
The two Ferraris of four-time champion Sebastian Vettel and Kimi Raikkonen will be on the second row ahead of Felipe Massa for Williams, Daniil Kvyat of Toro Rosso and Valtteri Bottas in the second Williams.
Dutch teenager Max Verstappen, who sensationally won the Russian Grand Prix on his debut for Red Bull, was ninth fastest ahead of Hamilton, who went into the weekend off the back of wins in Monaco and Montreal as he bids for a third straight world title.
"I couldn't tell you what the possibilities are for tomorrow," he said.