In the closest finish in 40 years, the USA played Spain for the men's basketball gold medal, in a thrilling rematch.