Samoa scored through hooker Pita Anae-Ah Sue and scumhalf Joel Lam as they rattled Fiji with an energetic start on Saturday in Rotorua.
A try to Seta Tamanivalu just before the break allowed Fiji to go to halftime only three points down at 15-12 and they took the lead for the first time with a try to scrumhalf Simione Kuruvoli in the 60th minute.
Fiji's win meant they finished atop Pool A in the Pacific Nations Cup and that Tonga also will go through to next weekend's semi-finals, which guarantees them a place at the 2027 World Cup in Australia.
With Fiji and Japan already qualified, the next three teams in the Pacific tournament qualify for the World Cup.
Samoa will play in a fifth- and sixth-placed playoff next weekend against the last-place team in Pool B, possibly the United States. The winner of that match also will qualify for the World Cup while the losing team will go into a inter-regional qualifier against a South American team.
Japan will play the United States in Sacramento, California, later on the weekend in the final pool match and the United States would have to win with a bonus point to avoid the playoff for fifth place.
The final and third-place playoff will be held in Salt Lake City on September 20.
Fiji also started slowly in their opening pool match against Tonga, conceding an early try before rallying to win 32-10.
Once again, they were rocked by an early try on Saturday as Anae-Ah Sue scored from a lineout drive.
Fiji struggled to get a foothold in the match because of Samoa's superior scrum and physical defence, and because of poor discipline.
The Fijians scored in the 13th minute through hooker and captain Tevita Ikanivere, also from a lineout drive but Samoa made the lead 15-5 when Lam scored off Melani Nanai's no-look pass.
Tamanivalu's try just before halftime was critical in Fii's comeback.