Giulia Gwinn netted the decisive goal, converting a penalty at the 65th minute after being awkwardly fouled by Spain’s goalkeeper, Cata Coll.
The match saw late drama as Spain were given a lifeline with a penalty just seven seconds before the final whistle, but Alexia Putellas was thwarted by an excellent save from goalkeeper Ann-Katrin Berger.
Spain had the best opportunity of an otherwise uneventful first half, with Aitana Bonmati striking the post shortly before halftime.
World Cup and Nations League champions Spain, participating in the Olympics for the first time, controlled possession in the closing stages and created several chances but couldn’t find the equalizer to push the match into extra time.
The win in Lyon secures Germany their fourth bronze medal, having previously done so in 2000, 2004, and 2008.
Brazil will face the United States in the gold-medal match at Parc des Princes on Saturday (16:00 BST).