India beat Spain to secure second consecutive men's hockey bronze medal
The win gave India's their second consecutive bronze medal as part of a 13-medal haul for the once-dominant side that won gold for six Games in a row from 1928 to 1956.
India goalkeeper PR Sreejesh was another driving force alongside their captain in his last international tournament, helping to turn away all but one of Spain's 15 shots, including a pair of saves in the closing minutes.
"You know, there's God's hand for the football, and this is how God always keeps it for me. The last save, again the same way. I'll celebrate that," Sreejesh told Reuters.
"What else do you want in your life? It's not an ordinary stadium, it's an Olympic stadium. And a medal, that's great.
"And I think for the last 24 years, what I've done, I dedicated my entire career to this game, and I think this is the best way to send me off by these guys."
Indian businessman Mukesh Ambani, the 11th richest person in the world according to Forbes, was in the stands to support the Indians as chants of 'India! India!' rang out during the match.
Spain opened the scoring in the 18th minute when skipper Marc Miralles put a penalty shot past Sreejesh after Manpreet Singh obstructed fellow midfielder Gerard Clapes in the circle.
Spain keeper Luis Calzado stretched to deflect a drag-flick by Harmanpreet less than two minutes before the end of the first half. Harmanpreet would not be denied, though, and scored with 15 seconds left on the clock on another penalty corner.
The second half opened with Harmanpreet netting the go-ahead goal on a penalty corner in the 33rd minute, his 10th goal at the Games giving him a clear lead as the tournament's top scorer.
India kept a tight defence and shut down Spain's attack for most of the second half. The physical contest saw several players from both sides helped off the field after collisions.
Spain took off Calzado in the 56th so substitute forward Borja Lacalle could come on as they tried to find an equaliser.
The Spaniards dominated possession towards the end but were unable to score as Sreejesh stood tall for India, making several key saves off penalty corners in the closing minutes.