Lewis Hamilton has put his Mercedes on pole for tomorrow's Hungarian grand prix. Team-mate Nico Rosberg is second and Ferrari's Sebastian Vettel is third.
The qualifying session was especially important because the twisty circuit makes overtaking difficult.
Red Bull's Ricciardo achieved fourth position ahead of the Ferrari of Kimi Raikkonen.
McLaren had another torrid qualifying session. Jenson Button failed to make it through the first part of the session and Fernando Alonso withdrew early in the second part because of yet another problem with his new Honda engine.
The following is the grid.
1. Lewis Hamilton (Britain) Mercedes 1:22.020 2. Nico Rosberg (Germany) Mercedes 1:22.595 3. Sebastian Vettel (Germany) Ferrari 1:22.739 4. Daniel Ricciardo (Australia) RedBull - Renault 1:22.774 5. Kimi Raikkonen (Finland) Ferrari 1:23.020 6. Valtteri Bottas (Finland) Williams-Mercedes 1:23.222 7. Daniil Kvyat (Russia) RedBull - Renault 1:23.332 8. Felipe Massa (Brazil) Williams-Mercedes 1:23.537 9. Max Verstappen (Netherlands) Toro Rosso - Renault 1:23.679 10. Romain Grosjean (France) Lotus - Mercedes 1:24.181 - - - - - - - - - - 11. Nico Huelkenberg (Germany) Force India - Mercedes 1:23.826 12. Carlos Sainz Jr (Spain) Toro Rosso - Renault 1:23.869 13. Sergio Perez (Mexico) Force India - Mercedes 1:24.461 14. Pastor Maldonado (Venezuela) Lotus - Mercedes 1:24.609 15. Fernando Alonso (Spain) McLaren - - - - - - - - - - 16. Jenson Button (Britain) McLaren 1:24.739 17. Marcus Ericsson (Sweden) Sauber - Ferrari 1:24.843 18. Felipe Nasr (Brazil) Sauber - Ferrari 1:24.997 19. Roberto Merhi (Spain) Marussia - Ferrari 1:27.416 20. Will Stevens (Britain) Marussia - Ferrari 1:27.949 - - - - - - - - - - 1-10: third and final qualifying session 11-15: second qualifying session 16-20: first qualifying session