The winning spot kick was subject to much debate but Rapinoe converted it with 15 minutes left, after her opening penalty had been cancelled out by Jennifer Hermoso early in the first half.
After breezing through the group phase, including a record 13-0 win over Thailand, holders USA lacked inspiration and conceded their first goal of the tournament as Spain rose to the occasion in searing heat at the Stade Auguste-Delaune.
France, who the U.S. will meet in Paris on Saturday (AEST) for a place in the semi-finals, scraped through the last 16 with a 2-1 win against Brazil after extra time on Monday.
"You can talk tactics but heart, grit and resolve - that’s a big part of World Cup soccer. No game is ever easy in this tournament," US coach Jill Ellis said.
"We know that, we’ve learned that. So part of it is the mental piece and I thought they were great tonight.”
Rapinoe added: "That’s World Cup level grit right there. You can’t replicate it, there’s no way to express it or teach it.
"The game’s only getting harder and more intense from here. Everybody is playing for their lives. That’s the best part about it honestly. I love it. This is the best stage.”