Helio Castroneves won his fourth Indianapolis 500 after overtaking Alex Palou in the closing laps of a thrilling 200-lap race.