Ten-man Wales sealed second spot in Group A and a place in the last 16 of Euro 2020, despite losing 1-0 to a much-changed Italy in Rome.
Ethan Ampadu's straight red card on 55 minutes had sparked fears Switzerland - who beat Turkey 3-1 - could come up with the goal difference swing they needed to send Wales into the uncertainty of a third-place qualifying spot.
But Rob Page's side battled hard in the heat of the Italian capital to set up a knockout clash with the runners-up of Group B in Amsterdam at 5pm next Saturday.
Matteo Pessina had given Italy a deserved lead (39) and Federico Bernardeschi hit the woodwork with a free-kick just after half-time as Roberto Mancini's team showed their strength in depth, although Gareth Bale should have claimed a famous draw for his side when he wastefully volleyed over late on.
Wales supporters will hope their captain - who missed a penalty in their last match - is sharper come next weekend, while Italy - who are now unbeaten in 30 games - look forward to facing the runners-up of Group C at Wembley later that day.
Italy: Donnarumma (6), Toloi (6), Bonucci (6), Bastoni (7), Emerson (6), Pessina (8), Jorginho (7), Verratti (8), Chiesa (7), Belotti (6), Bernardeschi (8).
Subs used: Acerbi (6), Raspadori (6), Cristante (6), Castrovilli (N/A), Sirigu (N/A)
Wales: Ward (8), Ampadu (4), Rodon (8), Gunter (7), C. Roberts (6), Allen (7), Morrell (6), N. Williams (6), Bale (6), Ramsey (6), James (6).
Subs used: Moore (7), Wilson (6), Brooks (N/A), Davies (N/A), Levitt (N/A)
Man of the match: Marco Verratti (Italy)
How Wales held out to book their last-16 spot...
Italy had made eight changes for the match but looked sharp from the first whistle, with testing crosses sent in by Alessandro Bastoni and Pessina before Emerson fired at Danny Ward from the edge of the box, and Pessina diverted an effort down the goalkeeper's throat a few minutes later.
Neco Williams, Ampadu, and Joe Allen combined down the left as Wales looked to spark into life and, after Andrea Belotti dragged a shot beyond the far post at the other end, the visitors registered their first effort on 27 minutes, with Chris Gunter's header clipping the side netting from a corner.
- Italy made eight changes, with only goalkeeper Gianluigi Donnarumma, Leonardo Bonucci and Jorginho keeping their place.
- Wales made three changes, with Ben Davies, Chris Mepham and Kieffer Moore making way Chris Gunter, Ethan Ampadu and Neco Williams.
Italy remained the more threatening side, though, with Federico Chiesa drilling a shot across goal and, after a tame Joe Rodon header on target from a free-kick, Italy made a set-piece of their own count.
Marco Verratti had begun to pull the strings for the Azzurri and, after he was fouled by Allen wide on the right, his clipped free-kick was glanced into the far corner by Pessina.
Italy almost doubled their lead before the break, with Verratti and Pessina again looking to combine, although the midfielder was unable to make a clean connection this time.
- How the teams lined up | In-depth stats and analysis
- Euro 2020 group tables | Who needs what to qualify for last 16?
Wales will have seen at half-time that Switzerland were two up against Turkey and were just a two-goal swing away from levelling the goal difference between the sides - and that gap almost closed in again when Bernardeschi curled a free-kick against the post eight minutes into the second half.
The visitors' task then got a whole lot harder two minutes later, when Ampadu came down on Bernardeschi's ankle with his studs in the middle of the pitch and was shown a straight red card.
A goal for Turkey temporarily improved Wales' position in the group but on the pitch they were becoming stretched, with Chiesa skipping past Williams and teeing up Belotti to fire at Ward before Rafael Toloi headed the resulting corner narrowly wide.
News of another strike for Switzerland was followed by a second bad miss in two games from Bale. He had sent a penalty way off target against Turkey and horribly miscued his left-foot volley unmarked eight yards out against Italy, to his disbelief and that of the Wales coaching staff.
That could have proved costly, with the Swiss hitting the woodwork late on and Ward saving well from Belotti in the final moments, but Wales held out and can now look forward to the challenge of repeating their knockout-stage heroics of Euro 2016.
What the managers said...
Italy manager Roberto Mancini to ITV: "We are happy, but we know that after the group stage we start a new European Championship. It will be different.
"The guys are very clever; they want to win every game and have a good mentality. We changed eight players and we played a very good game. We played against a good team, but I think we deserved to win."
Wales manager Rob Page: "We've got second spot and it's that feeling of winning. We knew we were in for a tough game and that we'd have to dig deep at times and we absolutely did that. Going down to 10 men gave us an even bigger hill to climb but credit to the boys, I can't speak highly enough of them."
Opta stats - Italy unbeaten in 30
- Italy are now unbeaten in 30 matches in all competitions (W25 D5) since losing against Portugal in September 2018, equalling the longest unbeaten run in their history, which was set between 1935 and 1939.
- Italy have kept a clean sheet in each of their last 11 matches in all competitions, only going on a longer run once before in their history - 12 games without conceding between 1972 and 1974.
- Despite losing today, Wales have now reached the knockout stages in all three of their appearances at major tournaments (1958 World Cup, Euro 2016 and Euro 2020).
- Aged 20 years and 279 days, Wales' Ethan Ampadu became the second-youngest player to be sent off in a European Championship match after John Heitinga (20 years 217 days) for the Netherlands vs Czech Republic in 2004, while Ampadu is the outright youngest to be shown a straight red.
- Italy's Marco Verratti led all players in this match for touches (136), passes completed (103), chances created (5) and tackles (4), as well as assisting the only goal of the game.
Group winners Italy will play the runners-up of Group C on Saturday at Wembley at 8pm, while Wales will face the runners-up of Group B on the same day in Amsterdam at 5pm.