They will now play the free-running Kenyans in the quarter-final but will be hoping a lack of concentration doesn't prove fatal again.
Wales were in total command against Tonga, jumping out to a 19-0 lead but 26 unanswered points by the South Sea islanders saw them stun the World Champions.
Wales led at the break after tries by Rhys Webb, Gavin Deacy and Arron Bramwell but the islanders hit back through captain Viliami Ma'afu, Sosaia Palei, Alaska Taufa and Nili Latu.
Eariler Wales brushed aside USA 24-17 with tries via Will Harries, James Merriman, Ifan Evans and Rhys Webb. USA hit back through through Mark Bokhoven (2) and Roland Suniula but Wales did enough to hold on.