The United States needed two Megan Rapinoe penalties, one of them controversially confirmed after a lengthy VAR review, to beat Spain 2-1 and set up a quarter-final clash with hosts France at the women's World Cup.
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, holders the US 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 US will meet in Paris on Friday for a place in the last four, scraped through the last 16 with a 2-1 win against Brazil after extra time on Sunday.
It took the US only seven minutes to break the deadlock as Tobin Heath was brought down in the area, with Rapinoe coolly converting the resulting penalty.
US goalkeeper Alyssa Naeher, however, was not at her best and poor positioning allowed Hermoso to equalise two minutes later with a lob into the net.
The champions were still all over Spain though and Rapinoe twice came close as Heath tormented the defence on the right.
Spain defended well although they lost midfielder Vicky Losada, who was replaced by Nahikari Garcia, because of swelling around her eye following a clash early in the game.
The Spanish centre backs did a great job at containing Alex Morgan and the U.S. seemed short of ideas up front.
Their salvation came when Rose Lavelle fell in the box after slight contact with Virginia Torrecilla, prompting referee Katalin Kulcsar to award a penalty, which was confirmed by VAR review to Spain's understandable frustration.
Rapinoe buried the spot kick and, with only 15 minutes left, the US controlled the rest of the game.
We need your consent to load this SoundCloud contentWe use SoundCloud to manage extra content that can set cookies on your device and collect data about your activity. Please review their details and accept them to load the content.Manage Preferences