Mikel Oyarzabal helped Spain into a second semifinal in a month. Brazil remains on track for a quick return to another final.
With youthful squads, Olympic men's football lacks the status of the European Championship or Copa America. The Tokyo Games still offer the chance for the countries to collect trophies this year.
The Spanish were taken by Ivory Coast to extra time before winning 5-2 on Saturday with Rafa Mir scoring a hat trick and the go-ahead goal from a penalty by Oyarzabal, who also netted the winning spotkick in a shootout in the Euro 2020 quarterfinals. The continental semifinal was lost to Italy. Now a more youthful Spain squad will be hoping to find a way past Japan, which was taken to penalties by New Zealand before winning the shootout 4-2.
The gold medalist on home soil in 2016, Brazil continued its title defense with a 1-0 victory over Egypt secured by Matheus Cunha's low strike in the 37th minute in Saitama.
Follow LIVE Coverage of 2020 Tokyo Olympics
The goal was set up by Richarlison, who has been allowed by Premier League club Everton to do double duty in the offseason, having already been in the side that lost to Argentina in the Copa America final three weeks ago.
Egypt wasn't allowed to bring players from England's top league like Brazil — particularly Liverpool striker Mohamed Salah as one of the three players over the age of 24 permitted in the men's competition.
"We had to take advantage of the few opportunities we had," Brazil coach André Jardine said. "We know from now on there won't be any more high scores for the rest of the tournament."
Brazil's opponent, standing in its way of reaching another final on Tuesday is Mexico, which ousted South Korea 6-3 with a pair of goals from Henry Martín in Yokohama.
The favorite for the title will be Spain given the high-caliber squad chasing its first Olympic soccer gold since 1992. This is the furthest it has reached in the competition since losing the final in 2000 to Cameroon.
It required a comeback at Miyagi Stadium in northern Japan after conceding to Eric Bailly's 10th minute-goal before Dani Olmo equalized. Then the Spanish came close to being eliminated again after Oyarzabal missed a chance to put them ahead just before Max-Alain Gradel put Ivory Coast in front in the first minute of stoppage time.
“I was thinking it would be so unfair for us to play so well and still lose,” Spain coach Luis de la Fuente said. “It helped me recover my faith in football that football can be fair after all.”
In part that's because Mir had been brought off the bench in the 90th minute and he salvaged an equalizer for Spain in the third minute of stoppage time. In extra time, Bailly's handball won the penalty that Oyarzabal converted. And it was a far smoother conclusion thanks to two more goals from Mir to complete a hat trick for the Wolverhampton forward.
“Things got difficult for a while in the match,” Mir said through a translator. “But I think at the end of the night we were all rowing the boat in the same direction. Everybody was plugged in completely and we are all working toward the same goal of bringing a medal home.”
It was even nervier in Kashima for Japan, which had to rely on goalkeeper Kosei Tane saving a penalty from Liberato Cacace and seeing Clayton Lewis miss the target before the shootout winner from captain Maya Yoshida.