Harry Wilson's stoppage-time goal secured victory for Wales Under-21s in their Euro 2017 qualifier against Armenia in Bangor.
Bristol Rovers striker Ellis Harrison's penalty put Wales ahead after Wes Burns had been fouled by Artur Kartashyan.
Gor Malakyan's header brought Armenia level before the hour mark.
But Geraint Williams' side sealed their third win of the campaign when Liverpool's Wilson fired past Anatoli Aivazov.
The win means unbeaten Wales go top of Group 5 with Williams' side hosting Romania in Wrexham on Tuesday, 17 November.
Wales Under-21 manager Geraint Williams told BBC Radio Wales:
"Fair play to them, they've kept going until the end and we've dug ourselves out of a little hole.
"They were two very different halves of football. I was very delighted with the first and very disappointed with the second.
"We were so on top in the first half and we didn't look anywhere near as comfortable in the second half."