With the game in the balance at 18-16 at halftime, Fijian halfback Henry Seniloli (three tries) and Ben Volavola (13 points) secured the win for the visitors.
Fiji had sealed its own qualification for the 2019 World Cup in Japan ahead of Saturday's match. But Samoa needed at least a bonus point in defeat to prevent Tonga claiming the second automatic qualifying place from Oceania.
With Samoa losing by more than 20 points, island neighbours Tonga now qualify for Japan while Samoa faces the prospect of a repechage match against the winner of Czech Republic or Portugal versus the second-place team in the 2016-17 Rugby Europe Championship.
Fiji will play in Pool D at the World Cup with Australia, Wales, Georgia and either Canada or Uruguay.
Meanwhile, Tonga will play in the World Cup's Pool of Death beside England, France, Argentina and the United States.
Photo: Fiji Rugby (Twitter)