Wales’ penultimate game before the World Cup ended in a 2-1 Nations League defeat to Belgium in Brussels.
Kevin De Bruyne and Michy Batshuayi rewarded Belgium’s first-half dominance with well-worked goals and Wales looked like they had to hide.
But Kieffer Moore halved the deficit five minutes after the break, and Robert Page’s side produced a much improved second-half performance to offer encouragement two months before the World Cup in Qatar.
Wales head into their final Nations League game at home to Poland on Sunday with their survival hopes intact.
Poland’s 2-0 loss at home to the Netherlands means bottom-placed Wales can leapfrog them with a win in Cardiff and remain in the top tier of European football.
Wales had been troubled by injuries, with Aaron Ramsey, Ben Davies, Harry Wilson and Joe Allen all missing.
Captain Gareth Bale was among the substitutes after arriving late at camp from the United States on Tuesday.
Bale, who was slowly building up to form in the United States ahead of the World Cup, had played for Los Angeles FC in the early hours of Monday morning UK time.
It was the ninth meeting between the two countries in the last decade, with Wales having held firm with two wins, two losses and four draws in that period.
De Bruyne had said before the game that he was so bored playing for Wales but the Manchester City midfielder didn’t show it as he produced a masterful performance.
Brennan Johnson had scored a late equalizer when the sides met in Cardiff three months ago, and the Nottingham Forest winger formed a three-pronged attack alongside Moore and Daniel James.
Belgium had seven starters in the side that lost to Wales in the Euro 2016 quarter-finals, including De Bruyne, Thibaut Courtois and skipper Eden Hazard.
Wales started confidently but fell behind after 10 minutes when Batshuayi’s cross found De Bruyne and he guided it casually past Wayne Hennessey, who got his hands on the shot.
Youri Tielemans and Hazard were inches from doubling the lead and De Bruyne, reveling in the generous space afforded him, fired a shot against a post.
De Bruyne quickly set up Belgium’s second after 37 minutes, rolling a defender superbly and crossing for Batshuayi to convert the simplest of tap-ins.
There was a brief respite for Wales as Joe Rodon closed in and Courtois parried Ethan Ampadu’s follow-up header.
But Wales were only spared further delay when Hennessey’s outstretched leg shoved another De Bruyne effort around a post.
Wales returned to the competition with a goal out of nothing.
Johnson twisted and headed for the Belgian box with a 40-yard run, and Moore rose at the far post to head home in style.
Wales sent Bale on just after the hour mark and he was soon in on the action, meeting a cross from James which was deflected off.
Belgium were awarded a penalty for a foul on De Bruyne. But replays showed Joe Morrell made contact with the ball and the decision was overturned in the VAR review.