Wales secured a much-needed, if not entirely convincing, win in Latvia to aid their ailing Euro 2024 qualifying campaign and ease some of the pressure on manager Robert Page.
Captain Aaron Ramsey rolled in a 29th-minute penalty after Harry Wilson was fouled, but Wales squandered a hatful of first-half chances against opponents ranked 134th in the world.
They were almost made to pay for their wasteful finishing, with Danny Ward saving from Janis Ikaunieks and Raimonds Krollis shooting narrowly wide as Latvia, pointless at the bottom of Group D, grew in confidence.
But as jittery as Wales were at times, a delicate dinked finish by substitute David Brooks in injury time sealed only their second win in 14 matches to move level on points with third-placed Armenia.
Wales still face a daunting task to reach Euro 2024 with only the top two teams in each group qualifying automatically.
And while just a second victory since June 2022 is welcome in any circumstances, this was against a limited Latvian team who succumbed to a ninth defeat in 10 home European Championship qualifiers.
Pressure on Page eases but doubts remain
Page's future has been the subject of intense scrutiny since he oversaw defeats in June against Turkey and, most damagingly, at home by Armenia.
Victory over Latvia lifts some of the gloom but, according to senior figures at the Football Association of Wales, Page's position will still be reviewed.
The former Northampton Town and Port Vale boss was a national hero last year when he became the first man to lead Wales to a World Cup since 1958.
However, after beating Ukraine in their World Cup play-off final in June 2022, Wales mustered only one win in their next 13 games, a 1-0 home victory over Latvia in March.
That run of poor form prompted stinging criticism from pundits and fans, many of whom have been calling for Page to be sacked.
Despite that discontent, Welsh supporters still outnumbered those from Latvia at the compact Skonto Stadium in Riga.
They watched their side seize immediate control of the match, creating a host of first-half chances starting with Brennan Johnson's shot over the bar from Ethan Ampadu's through ball in the second minute.
Ben Davies and Wilson each forced saves from Latvian goalkeeper Roberts Ozols - brought in after they were thrashed 5-0 in Croatia on Friday - while Neco Williams and Connor Roberts also missed opportunities.
Having survived nearly half an hour of sustained pressure, Latvia fell behind due to a moment of their own stupidity as Kaspars Dubra barged into the back of Wilson to give Wales a penalty, which Ramsey coolly stroked into the bottom left corner with Ozols going the other way.
Wales wasted further chances and, although they should have been out of sight, Page's men showed signs of fragility as Latvia came close to equalising shortly before the break with Ikaunieks denied by Ward.
Even against such lowly opponents, who Wales should have been leading by a comfortable margin, this was a reminder of why Page and his players had struggled so badly of late.
After Johnson wasted another couple of openings at the start of the second half, Latvia threatened again as a low 20-yard shot from Krollis whistled just past the post.
The hosts were perhaps fortunate to keep 11 players on the pitch when Ikaunieks was booked for a wild lunge at Jordan James, which was reviewed by the video assistant referee, but not upgraded to a red card.
Wales' players were incensed by that decision and seemingly galvanised as Williams again went close as he had a shot saved by Ozols, but Latvia were still a threat as Ikaunieks curled a shot into the side netting.
Finally, deep into injury time, Wales settled their nerves as Wilson played in Brooks and he lifted a delightful left-footed finish over Ozols and into the net to delight the rowdy travelling Welsh fans.
Winning whatever way possible was the objective for Wales in Riga and, in that respect, this was a mission accomplished.
But Page knows there will need to be further and greater improvements if he is to remain manager in the long term.