La Roja defeated Ivory Coast in extra time to ensure they advance to the final four, while Mexico eliminated South Korea to draw with Brazil
The tournament host Japan meets Spain in the semifinals of the Olynpics.
Japan beat New Zealand on penalties on Saturday to secure a place in the final four.
The two sides played 120 minutes in the Kashima Soccer Stadium aimlessly to undertake the showdown in a showdown, and Japan won 4-2.
Who else is in the semifinals?
Spain have meanwhile been almost knocked out of the competition in their clash with Ivory Coast, but a half-time goal from Rafa Mir makes it 2-2 and takes the game into extra time.
Mikel Oyarzabal scored a penalty in the first half of extra time, before La Roja went through with another 5-2 victory with two more goals from Mir.
Japan or Spain meet Brazil or Mexico in the final of the tournament.
Brazil won 1-0 against Egypt thanks to a goal in the first half from Matheus Cunha.
Mexico, on the other hand, dominated against South Korea to ensure that their hopes of winning a medal still existed.
Henry Martin, Luis Romo and Francisco Cordova beat El Tri 3-1 at halftime.
Korea pulled one back in the second half to give them a chance, but three minutes later Mexico regained their lead. Goals from Cordova and Eduardo Aguirre progressed even further before Ui-Jo Hwang struck to make it 6-3.
When is the semi-final played?
The two semi-finals will be played on Tuesday 3 August.
The clash between Brazil and Mexico in Kashima will begin first, with Japan and Spain fighting later in Saitama.
When is the final?
The lost semifinals will decide which team will win the bronze medal on 6 August.
Then the other two sides will pack the next day in Yokohama for the gold and silver medals.