The match was so old, past 10 p.m. at historic Old Trafford, that Hope Solo walked back toward her goal line, stared out at a spot on the ground in front of her, and prepared for penalty kicks. The U.S. women’s soccer team has won games that way before, and if that’s the wildest way to end things, then this match — this crazy match against Canada in the Olympic semifinals — must end that way.

But in the moments before Solo fully settled in, Heather O’Reilly, who spent the first 101 minutes on the bench, settled the ball on the right side. With her fresh legs, she sent a cross into the box in hopes that it might find an American head, an American foot, something. And Alex Morgan jumped.

“I need to wrap my head around what just happened,” Solo said.

What just happened, in the simplest terms, is that Morgan got her head on O’Reilly’s cross and knocked it past Canadian goalie Erin McLeod in the third minute of injury time at the end of 30 minutes of extra time — essentially with about 20 seconds left in a game that had lasted nearly 130 enthralling, exhausting minutes. The goal gave the Americans, who trailed three times, a 4-3 victory over Canada, and set up the rematch with Japan that the United States has yearned for since last summer, when it fell to the Japanese in the Women’s World Cup.

“Moments like this are what make sports so cool,” U.S. star Abby Wambach said.

But in between the jubilation and despair there was also controversy that complicated matters. The Canadians flat-out believe they were robbed — particularly on the game-tying goal, but throughout a rough-and-tumble game as well. They will wake up Tuesday morning believing the three goals delivered by brilliant forward Christine Sinclair should have been enough to stake their own place on Thursday at London’s Wembley Stadium, where the gold medal game will be contested.

“Just devastated,” Sinclair said. “We feel like we didn’t lose. We feel like it was taken from us. It’s a shame that in a game like that, that’s so important, the ref decided the result before it started.”

Sinclair put Canada up 1-0 at the half, and even at this legendary home to Manchester United, a normal soccer match seemed to be playing out before a crowd of 26,630 that at times sounded much larger. American Megan Rapinoe scored to tie things up on a corner kick, then Sinclair countered, then Rapinoe again, a rocket that clanked off the post and in. When Sinclair headed one more past Solo in the 73rd minute, a mad flurry of four goals in 19 minutes was over. With Canada up 3-2, there was more than a little spice.

There was also some discussion from the Americans about their propensity for providing drama, even if it makes no one in the stands very comfortable.

“I think we’re just trying to gain more fans,” midfielder Carli Lloyd said. “I think we’re trying to give people back home heart attacks.”

There were sources of calm. Wambach, 32, remained serene in so many unsettled moments, in large part because of the women with whom she plays.

“Even when they scored their third goal, there was something in me that knew that we had more, that we could give more,” Wambach said. “I don’t know what that means, quite honestly, if it’s just confidence until the end. But this team has a belief in itself.”

With a little more than 10 minutes remaining in regulation, McLeod, the Canadian goalie, wrapped up a ball on the ground, then took her time getting up. Here, then, came the controversy. Referee Christiana Pedersen of Norway called McLeod for holding on to the ball for more than her allotted six seconds, essentially a delay of game. Pedersen awarded the Americans an indirect free kick inside the penalty area. McLeod was stunned.

“I have never known this to happen in a game before,” she said. “Referees never make this kind of decision.”

The United States hardly debated that. American veteran Christie Rampone is 37 and has played on the national team for 15 years. When has she seen that call?

“Never,” she said.

Rapinoe took the free kick, and she drilled it directly into Canada’s wall of defense. It hit Canadian defender Marie-Eve Nault, ostensibly in the hand or forearm. Pedersen blew her whistle again: hand ball. Penalty kick, United States.

Sinclair, the Canadian captain, continued to ask for explanations.

“She actually giggled and said nothing,” Sinclair said of Pedersen. “Classy. . . . We feel cheated.”

Wambach knocked home the tying goal. At that point, who knew more than 40 minutes of soccer remained? In the 101st minute, O’Reilly arrived. She settled in. And later, with the clock ticking down, she looked for Morgan.

“This is what we live for,” Morgan said.

And because she got her head on that ball, the Americans have another moment for which to live. That it is against Japan is only appropriate.

“This is a rematch,” Lloyd said. “This is redemption for us. We know how bad it was for us after that game. We know how it felt.”

They also, time and again, know how it feels to win in pit-of-the-stomach fashion. When it was over, in the bedlam of a full-on pigpile, Wambach found Morgan and said, “I think I’m in love with you right now.” When the pile broke up, U.S. Coach Pia Sundhage found Morgan, too, and delivered a message.

“Remember one thing,” she said. “Promise yourself one thing: Remember this moment.”

It should not be difficult. That moment — one pass, one shot, one goal — ended a ridiculous night, put the Americans in the gold medal game, and provided a memory that couldn’t possibly be scrubbed from the brains of those involved.