The nine-time World Champion edged Acosta in a thrilling Hungarian GP pole battle, with Fermin Aldeguer taking third to complete the front row.