Nico Rosberg will start on pole position for the inaugural European GP to be held at the Baku City Circuit in Baku, Azerbaijan.

Rosberg's lap - a 1:42.758 - came in the closing minutes of the session, just before the red flag was flown for his teammate Lewis Hamilton, who clipped the wall after a frustrating qualifying session.

In Q2, there was a scare for Hamilton as he overshot a turn in the closing minutes of the session, narrowly avoiding the wall. Although he was able to get back on track and set a lap that put him into Q3, his tires are badly flat-spotted and, in theory, are the tires he will have to start the race on on Sunday.

More from FoxSports

In Q3, Hamilton had also had an off before his incident. While Rosberg and Hamilton had been struggling, Sergio Perez looked to be the provisional pole-sitter, but Rosberg's lap pushed him back to second. Perez will have to start from seventh anyway, as he was handed a five-place grid penalty after his team changed his gearbox following a crash in FP3.

Daniel Ricciardo and Sebastian Vettel locked out the second row with the exact same time - but Ricciardo will start ahead as he set his lap just before Vettel. They will start second and third with Perez's penalty. Both laps were set during a two-minute shootout at the end of Q3, following the red flag.

Meanwhile, Perez's teammate Nico Hulkenberg qualified in 12th after a radio mix-up, in which he believed the team had told him that he didn't have to finish his run.

Due to the long main straight, the Mercedes-powered teams had an advantage over the others, which helped see the Manor team qualify on the ninth row for the event while the factory Renault team will start from the rear.

Unofficial starting grid:

1. Nico Rosberg - Mercedes
2. Daniel Ricciardo - Red Bull
3. Sebastian Vettel - Ferrari
4. Kimi Raikkonen - Ferrari
5. Felipe Massa - Williams
6. Daniil Kvyat - Toro Rosso
7. Sergio Perez - Force India (after 5-place grid penalty)
8. Valtteri Bottas - Williams
9. Max Verstappen - Red Bull
10. Lewis Hamilton - Mercedes
11. Romain Grosjean - Haas
12. Nico Hulkenberg - Force India
13. Carlos Sainz - Toro Rosso
14. Fernando Alonso - McLaren
15. Esteban Gutierrez - Haas
16. Felipe Nasr - Sauber
17. Rio Haryanto - Manor
18. Pascal Wehlrein - Manor
19. Jenson Button - McLaren
20. Marcus Ericsson - Sauber
21. Kevin Magnussen - Renault
22. Jolyon Palmer - Renault