Argentina will move to Santa Fe for a quarter-final on Saturday 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.
Messi was supreme laying on chances for the forwards and Argentina should have doubled their tally against a raw, mainly under-23 Costa Rica side that was drafted into the tournament at the last minute after Japan pulled out.
"We needed to regain security as a team, with the ball... Lionel knows how to overcome these situations and today he showed that on the pitch with a tremendous match, fantastic," coach Sergio Batista told a news conference.
Aguero put Argentina ahead with the last kick of the first half, taking advantage of a deflection from a shot by Fernando Gago to bury the loose ball when the packed Costa Rica defence tried to clear a dangerous move in their box.
The striker also hit the second eight minutes into the second half after being put away by Messi on the left to become the tournament's top scorer with a tally of three.
"The truth is this victory means a lot. It was a final because it was our qualification and we did it," an elated Aguero told a television reporter on the pitch of the Mario Alberto Kempes stadium packed by more than 50,000 fans.
BRILLIANT THIRD GOAL
Messi, finding more space once Argentina were ahead, laid on a string of perfect balls to the strikers, his combination with Angel Di Maria perfect as the midfielder came in from the left to fire the third goal into the roof of the net in the 64th.
"The other two matches were very hard and we couldn't display our game but today the lads had a lot of confidence," Batista said following a 1-1 draw against Bolivia and a goalless stalemate with Colombia.
Argentina were unlucky not to be awarded a penalty just past the hour when Gonzalo Higuain was pulled back but the striker was also guilty of several missed chances.
Central defender Nicolas Burdisso had a header from a corner come off the angle of bar and post in the first half.
The only difficult ball Argentina's goalkeeper Sergio Romero had to deal with was a header from an 89th-minute corner that he dived to punch away.
Costa Rica seldom managed to venture into Argentina's half and only came marginally close to a chance in the first half with a shot from outside the box by shaven-headed midfielder Heiner Mora that went just over the bar.
Now the Costa Ricans must wait to see if they squeeze into the last eight as one of the two best third-placed teams.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.