Aprilia's Aleix Espargaro overtook Marc Marquez and Francesco Bagnaia as he closed to within 0.729s of victory in the Qatar MotoGP Sprint.