Portugal have claimed the last place in the 2023 men's Rugby World Cup in France, after snatching a 16-16 draw against USA in their final qualifier.
They won the four-team final qualifying tournament in Dubai on points difference with a last-minute penalty.
Portugal will be in Pool C alongside Wales, Australia, Fiji and Georgia.
They will take on Wales in their first match in Nice on 16 September, although Wales start six days earlier against Fiji.
It is only the second time Portugal, coached by former France wing Patrice Lagisquet, have qualified in 10 World Cups and the second time the USA have missed out.
The Eagles' failure is a blow for the country, who will host the 2031 tournament and the 2033 women's event.
Wales and Portugal have only met once before, in a World Cup qualifier in 1994, when Wales ran up a 102-11 victory as wing Nigel Walker ran in four of their 16 tries.
Both sides in the decisive qualifier had comfortably dispatched Hong Kong and Kenya in their repechage play-off tournament, with Portugal going into the match ahead on points difference and one place higher in the world rankings at 18th.
Portugal scored the only try of the first half after eight minutes when wing Raffaele Storti crossed, with his opposite number Nate Augspurger in the sin-bin for a late tackle.
Scrum-half Samuel Marques landed a conversion and penalty while Bristol Bears fly-half AJ MacGinty kicked three penalties from four attempts for the Eagles, to leave Os Lobos a point ahead at the interval at 10-9.
Marques added a further penalty but missed two more attempts, and the USA finally crossed the line in the 60th minute through a short-range effort from Saracens hooker Kapeli Pifeleti converted by MacGinty, with Portuguese prop Francisco Fernandes yellow-carded to rub salt into the wound.
But Portugal held on knowing that a draw would take them through and launched a last-ditch attack, earning a penalty shot which Marques landed from 30 metres after Jeronimo Portela's drop-kick had hit the post seconds earlier.
"It's one of the best feelings in the world when hard work pays off, it's simply unbelievable," said Portugal captain Tomas Appleton.
"For the rugby community this is amazing, we've missed it quite a few times (after 2007) and we need a new generation to inspire young kids to play rugby.
"Our coach Patrice [Lagisquet] has done an amazing job to get the players into a strong unit and the hard work pays off."
Meanwhile, in the other third-round match in the qualifying tournament, Hong Kong came from 18-7 down to defeat Kenya 22-18 and take some consolation from their visit to Dubai.