Spain beat Ivory Coast in extra time to ensure their progress to the final four while Mexico trounced South Korea to set up a tie with Brazil on Saturday, reports goal.com.
Tournament hosts Japan will meet Spain in the Olympic semifinals as they beat New Zealand on penalties on Saturday to secure a place in the final four.
Spain, meanwhile, were almost knocked out of the competition in their clash with Ivory Coast, but a stoppage time goal from Rafa Mir made it 2-2 and took the game into extra time.
Mikel Oyarzabal scored a penalty in the first half of extra time before two more Mir goals saw La Roja go through with a 5-2 win.
Brazil went through with a 1-0 win against Egypt thanks to a first-half goal from Matheus Cunha.
Mexico, on the other hand, dominated against South Korea to ensure their hopes of picking up a medal are still alive.
Henry Martin, Luis Romo and Francisco Cordova struck to give El Tri a 3-1 half-time lead.
The two semifinal ties will be played on Tuesday.
The clash between Brazil and Mexico in Kashima will kick off first, with Japan and Spain going head-to-head in Saitama later on.
The losing semifinalists will go ahead to decide which team gets the bronze medal on August 6.
Then, the other two sides will face off for the gold and silver medals the following day in Yokohama.