KTM stand-in Pol Espargaro comes out on top of a last-lap duel with Francesco Bagnaia at the Hungarian MotoGP.