The U.S. women’s soccer team advanced, barely, to the semifinals of the Olympics. The Americans edged the Netherlands in a penalty-kick shootout, 4-2, Friday in Yokohama after regulation ended in a 2-2 tie.

Lynn Williams was the star of the game early, delivering a goal and an assist in her first start of the tournament. Dutch star striker Vivianne Miedema was outstanding, with a pair of dazzling goals.

But at the end, the standout player was American goalkeeper Alyssa Naeher. The Penn State product stopped two penalties in the shootout and one in regulation, and made a full-stretch diving save in the 103rd minute to keep the score level.

Early in the game, Williams and Tobin Heath led the U.S. in delivering the kind of high-pressure defense fans had waited all tournament to see. But the Netherlands opened the scoring in the 19th minute. Miedema turned in tight space with the ball and dismissed Kelley O’Hara and Abby Dahlkemper to set up an inch-perfect low shot.

Nine minutes later, Sam Mewis pounded in a header off a cross from Williams — a badly needed bright spot from Mewis after she played poorly in the last game. Three minutes after that, Williams pounced on a bouncing ball after a corner kick and thumped it in to put the Americans ahead.

Miedema struck again in the 53rd with a dazzling 23-yard strike after a tough run into the heart of the U.S. defense, her record 10th goal of these Olympics.

U.S. manager Vlatko Andonovski responded with a triple attacking sub: Rose Lavelle for Mewis, Alex Morgan for Lloyd, and Christen Press for Williams — the last of which was surprising given how well Williams was playing. Taking off Heath seemed a better idea on form. But Heath left in the 63rd anyway, for Megan Rapinoe, and Press nearly scored off the restart but was a fraction offside.

There followed a stretch of the kind of high-strung tension that makes tournament soccer so special. It was shattered in the 79th, when O’Hara took out the Netherlands’ Lineth Beerenstyn in the middle of the 18-yard box, drawing an immediate penalty-kick call from referee Kate Jacewicz.

But Naeher stoned Lieke Martens’ low attempt to keep the score at 2-2.

So it was back to that tension, including unusual breakdowns on scoring chances by Morgan and Press. And eventually, it was on to 30 minutes of extra time that were just as dramatic.

The Dutch often looked better, and the Americans often looked like a team with six players over the age of 30. Rapinoe looked especially slow, though she nearly scored in the 99th after a couple of pretty cutbacks from the left wing.

Only two options were left for field-player substitutions at that point: defender Emily Sonnett and midfielder Kristie Mewis. Andonovski had chosen Sonnett for the bench over Tierna Davidson, and that might have backfired. Davidson could have come in for Horan and gone to left back, allowing Dunn to move into midfield.

Yet Press and Morgan nearly brought redemption in the second extra time period, each breaking free and scoring, only to be found offside. The video replay booth confirmed each call to be correct — the eighth and ninth times in these Olympics that the U.S. lost goals for being offside.

When the game headed to penalties, American fans didn’t need reminding that the 2016 quarterfinal loss to Sweden ended this way. But this time, the U.S. came out on top.

Naeher stopped Miedema right out of the gate, giving the U.S. an edge before any of its takers had to step up. Lavelle, Morgan, and Press scored confidently, and Naeher stopped Aniek Nouwen.

Then came Rapinoe, the ultimate penalty-kick taker. She smashed it in, and the U.S. was off to the semifinals.

“The beauty of this team is, when things aren’t going right, we’re still getting results,” Williams said. “And I think that’s what you saw tonight — that we’re never going to give up until the very last whistle is blown. I’m proud of us, and we’re going to keep going.”

The Americans will face old rival Canada on Monday at 4 a.m. (USA Network, Telemundo), thanks to the Canucks’ upset of Brazil on penalties after a scoreless tie.

The other semifinal, set for Monday at 7 a.m. (USA Network, Telemundo), will see Sweden face Australia in a rematch of a group stage game. Sweden eliminated host Japan, 3-1, and Australia ousted Britain in a wild 4-3 contest.

More video highlights