Copa América - Messi sends Argentina through
Sergio Aguero scored twice with Angel Di Maria also on target, but it was the performance of Messi that had the home fans drooling after a couple of indifferent performances in the opening two games of the tournament.
The Barcelona playmaker threaded a beautiful ball into the path of Aguero for the second goal on 52 minutes before doing likewise for Di Maria to thump home the third of the night on 64 minutes before a crowd of 57,000 expectant supporters in Cordoba.
Argentina could have had more than three goals as they overwhelmed a young Costa Rican side, who failed to force home goalkeeper Sergio Romero into making a save until the 87th minute when he clawed out Jose Cubero's powerful header.
The former world champions piled bodies forward throughout the match, but had to wait until the first minute of time added on at the end of the first half when Aguero struck after goalkeeper Leonel Moreira had failed to hold Fernando Gago's deflected drive.
Sergio Batista's side never looked back from that moment onwards.
Having drawn 1-1 with Bolivia and been held to a goalless draw with Colombia - who win the group on seven points, two ahead of the second-placed Argentina - the pressure was well and truly on the host nation.
Costa Rica went into the match needing only a draw having downed Bolivia 2-0 in their second group match.
It became evident early on that it was going to be a long night for them as Argentina, with Di Maria, Gonzalo Higuain, Aguero and Gago drafted into the starting line-up after they had been booed from the pitch against Colombia.
Higuain could easily have grabbed a couple of goals in the opening 12 minutes as he forced Moreira to save before flashing a shot wide of the target minutes later.
Aguero walloped wide of the goal from distance on 22 minutes as Argentina set up camp in the opposition half.
Moreira saved from Higuain on 25 minutes before Nicolas Burdisso clattered the bar with a header around the half-hour mark.
The goal was inevitable when it arrived, even if there was an element of luck about it as Gago's effort took a wicked deflection that Moreira could not hold before Aguero converted.
With Messi at the heart of every Argentina move, Higuain should have put his side three to the good when he lifted a shot over the bar after Aguero had made it two from Messi's pass.
They were denied a certain penalty when Higuain was manhandled by Sergio Duarte as he sped through on goal, but that could not take the shine off a delightful performance.
Messi played in substitute Ezequiel Lavezzi five minutes from time. The Napoli man hit a post when it looked easier to score.
Lavezzi will take no part in the quarter-finals after a silly late challenge on Diego Madrigal in stoppage time saw him pick up a yellow card for an automatic suspension after an earlier booking in the tournament.
Argentina will move to Santa Fe for a quarter-final against the second-placed team in Group C, while group winners Colombia's last-eight match is in Cordoba with the best third-placed team from the three groups.