It was Argentina's first win at this year's Copa América after opening with a 2-0 loss to Colombia and a 1-1 draw with Paraguay.
Argentina struggled again on Sunday, unable to impose its game against the Asian champion. Messi again was far from his best, unable to spark his team into a dominant performance.
Martinez opened the scoring only four minutes into the match after a mistake by Qatari defender Bassam Al Rawi while trying to pass to a teammate in front of his area. Martinez intercepted the pass and found the net to open the scoring at the Arena Gremio.
Qatar, making its first appearance as a guest in the Copa América, stayed in contention during most of the match but Aguero sealed Argentina's win with a run past a couple of defenders in the 82nd.
"The pressure was there," Argentina coach Lionel Scaloni said. "Luckily we got an early goal."
Argentina's last title with the senior team was the 1993 Copa América. It has come close to victory in recent years with Messi, losing in the final in the World Cup in 2014 and in the Copa America in 2015 and 2016.
Argentina entered the match last in the group, knowing only a victory would guarantee its place in the next round. Qatar, led by Spanish coach Felix Sanchez, was making its first appearance as a guest in the Copa América, hoping to gain experience for when it hosts the 2022 World Cup. It was eliminated despite opening with a gritty 2-2 draw against Paraguay and a late loss to Colombia.
Qatar will also play in next year's Copa América co-hosted by Colombia and Argentina.
Venezuela, Argentina's next opponent, was second to Brazil in Group A. It drew 0-0 with the hosts in its second game in the Copa América.
"It will be a difficult opponent," said Scaloni, whose team lost 3-1 to Venezuela in a friendly in Madrid in March. "It's an interesting team, it has been playing together for a long time."