Aguero had scored Argentina's only other goal across its opening two draws, making him the tournament scoring leader with three.
Angel Di Maria scored Argentina's third goal in the 64th in a performance that will revive the host nation's pre-tournament expectations of challenging for the title and ending an 18-year drought in major championships.
Argentina improved to 5 points in three matches and finished second in Group A. Colombia was first with 7 points. The top two teams in each of the three groups advance, along with the best two third-place teams.
Group B and C will be settled on Tuesday and Wednesday. Despite the loss, Costa Rica is not eliminated and awaits outcomes in the other groups.
Argentina applied constant pressure in the first half before Aguero broke through just before the interval, putting a rebound past Costa Rica goalkeeper Leonel Moreira.
In the 52nd he took a through ball from Messi and tucked his shot inside the far post, as Argentina continued to dominate.
It was Messi again who set up the third goal, finding Di Maria who ripped the ball into the net from 15 meters (yards).
Argentina coach Sergio Batista fielded an attacking lineup, with Aguero, Gonzalo Higuain and Di Maria playing in front of playmaker Messi. Forwards Carlos Tevez and Ezequiel Lavezzi started on the bench after two poor matches.
The new lineup seemed to suit Messi, who finally looked at ease as Argentina dominated the first half from the opening whistle and could have scored four or five from a dozen threatening attacks.
Costa Rica coach Ricardo La Volpe, who was born in Argentina, chose to play for a draw from the start.
Costa Rica and Mexico are both playing largely under-23, Olympic-style teams in this tournament, as both are guest teams in this tournament, and used their first-choice squads in last month's Gold Cup in the United States.
Argentina: Sergio Romero, Pablo Zabaleta, Nicolas Burdisso, Gabriel Milito, Javier Zanetti, Fernando Gago, Javier Mascherano, Angel Di Maria (Lucas Biglia, 79), Lionel Messi, Sergio Aguero (Ezequiel Lavezzi, 84), Gonzalo Higuain (Javier Pastore, 79).
Costa Rica: Leonel Moreira, Johnny Acosta, Francisco Calvo (Randall Brenes, 45), Oscar Duarte, Jose Salvatierra, Pedro Leal, Heiner Mora, Jose Cubero, Cesar Elizondo (Luis Miguel Valle, 56), Josue Martinez (Diego Madrigal, 45), Joel Campbell.