Germany, the clear favorite in this match, generated danger early on, but could not make it count.
Germany finished with three points after the loss and makes its first opening-round exit since 1938.
Mexico left back Jesus Gallardo received a yellow card for elbowing Sweden's Ola Toivonen just 13 seconds into the match, the quickest a player has ever been booked in the World Cup. "They were so disciplined, so loyal in everything they did", coach Janne Andersson said. "I am not going to sit here and gloat having won a match or boast about a win".
"For the first time in many, many games when we play against a team that play that approach, direct football, we had this formation".
Sweden's Marcus Berg reacts in pain after suffering a penalty from Mexico's Hector Moreno, left, during the group F match between Mexico and Sweden, at the 2018 soccer World Cup in the Yekaterinburg Arena in Yekaterinburg, Russia, Wednesday, June 27, 2018.
The Swedes started the day in third place in Group F, but Ludwig Augustinsson's volley (50), Andreas Granqvist's penalty (62) and Edson Alvarez's calamitous own goal (74) saw them leap to the top spot with a tremendous display in Yekaterinburg.
Your England team to face Belgium in final group game
I don't think it would be professional of us to put those players at a risk of missing the knockout phase. Photo Gareth Southgate wants to keep experiencing that winning feeling.
Despite a late onslaught, Germany could not find a breakthrough. Next up, Mexico could be facing Brazil in the round of 16 if the South Americans win Group E.
Sweden will now play the second-placed side in Group E - currently Switzerland - in St Petersburg on Tuesday afternoon.
Berg posed repeated problems for the Mexican defence, his best chance coming when his well-struck shot was acrobatically turned over the bar by goalkeeper Guillermo Ochoa. Granqvist stepped up to take the penalty and duly converted it.
"We always knew we would have to fight all the way to the last game", Ochoa said. "I was not happy how we defended, it was a learning experience for me".
"We qualified because we beat Germany and Korea but nevertheless I am very hurt", he said. "However and nevertheless, I am very hurt".
Alvarez's own goal was the seventh overall of the tournament, the most in World Cup history, breaking the record of six set in 1998.
Jimmy Durmaz, the winger who was racially abused online after giving away the free-kick that led to Germany's victor, is again on the bench for Sweden. Once again the players have been highlighting the importance and value of the strong unity within the group. Costly mistakes enlarged the score, and at the 90th minute, Sweden walked away with a 3-0 victory. They were still in position to advance despite trailing Sweden, but they were waiting - some with tears in their eyes - for Germany to do the inevitable and ruin their chances of moving on.