The visitors failed to come out of Estadio Nacional with a point but finished fourth in Concacaf qualifying to set up a play-off with New Zealand for a place in Brazil
As was the case during their entire qualifying campaign, nothing came easy for El Tri, who finish fourth despite the defeat after United States's 3-2 victory over Panama. As a result, they will enter a home-and-away play-off with New Zealand in November for a place at World Cup 2014.
Real Salt Lake forward Alvaro Saborio, a second-half substitute, scored the winner for Costa Rica, powering a free header past Guillermo Ochoa in the 64th minute.
That goal seemed to have put Mexico out of World Cup contention after Panama took a 2-1 lead over USA but Graham Zusi's late goal and Aron Johannsson's winner turned things around and eliminated the Americans' hosts.
Mexico battled from behind for much of the night but not before having the chance to seize control of the game early on. After a sharp passing sequence sent Oribe Peralta through behind the defence, the Santos Laguna forward squared his ball to Chicharito as goalkeeper Keylor Navas raced off his line.
The Manchester United star attempted to hit a first-time shot into the vacant net but scuffed it and it was deflected off Peralta, who was standing in an offside position by the far post and thereby ended the move.
Mexico were made to rue that miss moments later, as Bryan Ruiz opened the scoring in the 25th minute. The Fulham man got in behind Mexico centre-backs Rafa Marquez and Hugo Ayala, latching onto a clipped, bouncing ball over the top and heading the ball to create space for himself as he turned and fired a left-footed volley past a helpless Ochoa.
As of that moment, considering Panama's 1-0 lead over USA, Mexico were out of the World Cup but Peralta pushed El Tri would jump back into fourth place just four minutes later. Again it was Chicharito who had a chance elude him as Navas came off his line to swat a ball off his foot in the area. Peralta was there to fire home a follow-up shot off the underside of the crossbar, though, to level the score.
Chicharito missed another opportunity at the end of the first half, with Peralta sparking the build-up with a ball down the right channel for Javier Aquino. The Villarreal winger crossed to the near post, where the striker was making his run, but he put his first-time chance into the side netting.
Chicharito departed in the 60th minute for Friday's goalscoring hero, Raul Jimenez, but not before picking up a yellow card that will have him suspended for the first leg against New Zealand.
Saborio, who replaced Ruiz in the 49th minute, put Costa Rica back ahead off a free header in front of Ochoa shortly afterwards, which put Mexico back out of the qualification places for just a moment until USA tied things up with Panama just seconds later.
Navas and Ochoa exchanged highlight-reel saves to preserve the 2-1 scoreline and Costa Rica midfielder Cristian Bolanos's miss off the far post in the 75th minute did the same. With Mexico unable to beat Navas and their fate resting solely in their rivals' hands, the Americans came through at the death to keep Victor Manuel Vucetich's side alive for at least two more games.