Samoa were ahead 6-0 before Wales responded through Jared Rosser's try.
Aled Ward, Sean Moore and two tries from Shane Lewis-Hughes gave Wales a commanding lead
Alexander Pohla-Murray and Setu Enoka crossed for Samoa but Dane Blacker, Will Griffiths and Joe Goodchild sealed a bonus-point win.
Wales had lost their opening two matches against Australia and England in Pool A.
The win with a bonus point was crucial for Wales, as Jason Strange's side now look likely to avoid being among the bottom four teams who will battle to avoid relegation to the second-tier U20 Trophy next year.
Ireland needed to beat New Zealand with a bonus point to overtake Wales in the rankings, but were crushed 69-3 by the junior Kiwis.
Wales' next game will be against Scotland in the fifth to eighth place play-offs on Tuesday, 13 June.
Wales U20: Phil Jones (Ospreys); Jared Rosser (Newport Gwent Dragons), Ioan Nicholas (Scarlets), Owen Lane (Cardiff Blues), Joe Goodchild (Newport Gwent Dragons); Ben Jones (Cardiff Blues), Reuben Morgan-Williams (Ospreys); Rhys Carre (Cardiff Blues), Owen Hughes (Newport Gwent Dragons), Kieron Assiratti (Cardiff Blues), Callum Bradbury (Cardiff Blues), Sean Moore (Pontypridd), Shane Lewis-Hughes (Cardiff Blues), Will Jones (Ospreys, capt), Aled Ward (Cardiff Blues).
Replacements: Ellis Shipp (Newport Gwent Dragons), Tom Mably (Cardiff Blues), Steff Thomas (Scarlets), Will Griffiths (Ospreys), James Botham (Cardiff Blues),  Dane Blacker (Cardiff Blues), Arwel Robson (Newport Gwent Dragons), Cameron Lewis (Cardiff Blues).
Wales Under-20 ran in eight tries to beat Samoa and secure their first win of the World Rugby U20 Championship in Georgia.