Miguel Oliveira took the race win as title rivals Enea Bastianini and Danny Kent crash out on the final lap at the Aragon GP.