Argentina will play Belgium in the quarterfinals.
Except for its final group-stage win over Nigeria, Argentina has won its matches in Brazil in the same manner grinding down its opponents rather than dazzling them with brilliant football.
In the first half Tuesday, Argentina struggled to find paths through Switzerland's five-man midfield, and it was the Swiss that produced the best chances.
Granit Xhaka pushed Sergio Romero to a great save and Josip Drmic spoiled a great opportunity when he tried to chip the ball over the Argentina goalkeeper.
When cracks started opening in the defense in the second half, goalkeeper Diego Benaglio kept Switzerland in the game, stopping Gonzalo Higuain's header and Messi's low shot in the 78th minute.
Benaglio also saved a powerful attempt by Di Maria in extra time, and it looked like the Swiss would be able to push the game into a penalty shootout.
Then, in the 118th, Rodrigo Palacio won the ball in midfield and fed Messi, who dribbled down the middle in trademark fashion, escaping a challenge from Swiss defender Fabian Schaer before poking the ball to Di Maria. Unmarked, the Real Madrid player beat Benaglio with his 10th goal in Argentina's colors.
"What's important is that we moved on to the next stage," said Messi, who has scored four of Argentina's seven goals, including an injury-time winner against Iran. "It was difficult. We knew it was going to be a hard match."
Swiss substitute Blerim Dzemaili nearly equalized right before the end but his header hit the post, and the rebound bounced off his knee and wide of the goal.
Switzerland coach Ottmar Hitzfeld, whose brother died at age 81 one the eve of the match, said his team leaves the tournament with "our heads high."
• Argentina 1,Switzerland 0
• Belgium 2, U.S. 1
• France vs. Germany, 10 a.m., ESPN2
• Brazil vs. Colombia, 2 p.m., ESPN
• Argentina vs. Belgium, 10 a.m., Ch. 4
• Netherlands vs. Costa Rica, 2 p.m., ESPN