PORTO, Portugal (AP)After Porto lost its first two Champions League matches this season, few expected the Portuguese side to advance from a group in which Atletico Madrid was the heavy favorite.

But when it all ended on Tuesday, it was Atletico lamenting a last-place finish and Porto celebrating the group win.

Porto defeated Atletico 2-1 to finish first in Group B and keep the Spanish team from making it to the Europa League playoffs.

Mehdi Taremi and Stephen Eustaquio scored first-half goals for Porto, which won its last four straight Champions League games to take over first place after Club Brugge was held to a 0-0 draw at Bayer Leverkusen in the other match. Porto finished with 12 points, one more than Brugge.

Porto had started its campaign with a last-minute loss at Atletico and an embarrassing 4-0 home defeat to Brugge.

”We didn’t get off to a good start but we knew that we only depended on ourselves,” Porto forward Pepe said. ”In the end we reached our goal.”

Atletico had already been eliminated and needed a win to secure third place and a spot in the Europa League playoffs. Instead, Leverkusen earned that berth because of a better head-to-head tiebreaker against Atletico, which finished last in a Champions League group for the first time.

It was also the first time since 2009 that Atletico has gone five matches without a win in the Champions League. At that time, it endured a nine-game winless streak that began in 2008.

”We didn’t deserve to make it to the round of 16 and we didn’t deserve to make it to the Europa League,” Atletico forward Antoine Griezmann said. ”When you can only win one of your matches in the group stage, that’s what you get. Now all we can do is shut our mouths, work hard and keep fighting.”

The loss will add pressure on coach Diego Simeone in what has been a lackluster season for Atletico. In the Spanish league, it sits in third place, eight points behind second-place Barcelona and nine points behind leader Real Madrid.

”The only way I know how to get out of situations like this is to stick together and get everyone involved – the club, the fans and ourselves,” Simeone said.

Simeone’s usually stout defense looked soft early on and Porto took advantage.

Taremi opened the scoring from close range five minutes into the match for his 12th goal in all competitions this season, and Eustaquio added to the lead with a strike from near the penalty spot on a breakaway in the 24th.

Taremi has scored 12 goals in 17 appearances in all competitions this season. He had scored two goals in each of Porto’s last two Champions League matches.

Griezmann thought he had pulled Atletico closer with a powerful shot into the top of the net in the 68th, but the goal was called off because of a foul by Atletico midfielder Rodrigo de Paul in the buildup.

Atletico scored with an own-goal by Ivan Marcano in stoppage time.

Porto has reached the last 16 or better in seven of its last 10 Champions League appearances, four of them during coach Sergio Conceicao’s reign.

It is only the second time in 10 seasons that Atletico failed to advance from the group stage, and first since 2017-18. It won the Europa League the last two times it didn’t advance in the Champions League – in 2018 and 2010.

Simeone started with Joao Felix playing alongside Griezmann up front as regular starter Alvaro Morata recovered from an injury. It was Felix’s first start in nine matches.

Porto was still without veteran central defender Pepe because of a knee injury.

Griezmann had scored a late winner to give Atletico a 2-1 win in the teams’ first meeting. Since then, Atletico lost at Leverkusen and at Brugge before being held to draws at home by those same clubs. Simeone’s team had a late chance to beat Leverkusen in the previous round but Yannick Carrasco missed a penalty kick awarded by video review deep into stoppage time.

Porto was coming off a 4-0 win at Brugge and a 3-0 victory at Leverkusen. It had also beaten Leverkusen at home after the 4-0 loss against Club Brugge at its Dragao Stadium.

AP World Cup coverage: https://apnews.com/hub/world-cup and https://twitter.com/AP-Sports