Harmanpreet double takes India to Olympic men's hockey bronze
Harmanpreet Singh scored from two penalty corners after Marc Miralles had given Spain the lead at the Yves du Manoir Stadium in Colombes, northwest of Paris.
It is India's fourth bronze medal, and second in succession following Tokyo, and adds to their eight golds, the last of which came in 1980, and one silver.
India have historically enjoyed the upper hand against three-time silver medallists Spain.
But after a cagey first half they found themselves trailing when Miralles fired an 18th-minute penalty stroke past "Wall of India" Sreejesh Raveendran, playing his 336th and final international.
Borja Lacalle almost made it two, beating Sreejesh only to see his shot rebound off the post.
With the country's richest man, Mukesh Ambani, supporting from the stands, India began to press hard and with just a few seconds remaining of the first half, Harmanpreet buried a penalty corner to level the scores.
Three minutes after the break, Harmanpreet repeated the trick, sweeping another penalty corner just inside the Spanish post.
It was his 10th goal of the tournament -- he is the top-scorer at the Paris Olympics.
Spain picked up the tempo in the final quarter, forcing a series of late penalty corners and one outstanding save from Sreejesh, which ensured that India would take the bronze medal.
World champions Germany face the Netherlands in the gold medal match later on Thursday.