PORTO ALEGRE   -   Lionel Messi avoided another disappointment with the national team as Argentina escaped elimination in the group stage of the Copa America.

Lautaro Martinez and Sergio Aguero scored a goal in each half as Argentina defeated guest team Qatar 2-0 to secure a spot in the quarterfinals of the South American competition. “We needed a victory to give us confidence and tranquility,” Messi said. “What I liked the most was the team’s attitude, its desire to win the game.”

Argentina finished second in Group B behind Colombia, which did Argentina a huge favor by beating Paraguay 1-0 in the other group match on Sunday. Colombia finished with nine points, Argentina four, Paraguay two and Qatar one. The top two teams in each of the three groups advance, along with the two best third-place finishers. Paraguay will advance only if Japan and Ecuador draw on Monday in Group C.

Argentina, which hasn’t been eliminated in the first round of the South American tournament since 1983, will face Venezuela in the quarterfinals at the Maracana Stadium in Rio de Janeiro. It was Argentina’s first win at this year’s Copa America 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 America, 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 America. 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 America, 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.

Colombia beat Paraguay at Copa America to stay perfect: Colombia beat Paraguay 1-0 Sunday with a second-string team to stay perfect at the Copa America with three wins and without conceding any goals. The win also helped Argentina to advance from Group B in second place.

The only goal of the match at the Arena Fonte Nova in Salvador was scored in the 31st minute by midfielder Gustavo Cuellar. Argentina beat Asian champion Qatar 2-0 in Porto Alegre to finish behind Colombia with four points. Paraguay got two points and guest team Qatar ended its Copa America participation in fourth, with one point.

Colombia will have to wait for Group C to finish on Monday to know who it will play in the quarterfinals. Colombia, a team that has won the Copa America only once in 2001, next faces the second-place team from Group C. Defending champion Chile leads that group with six points and plays Uruguay with four points. “If you have a dream and you want to be champion, you need to have a group of players that are ready to play,” said Colombia coach Carlos Queiroz. “The true Copa America begins now.”

Paraguay must hope for a draw between Japan and Ecuador in Group C to advance as one of the two best third-place finishers. With its spot secured in the knockout stage, Colombia used an alternative lineup.