The game was locked 3-3 at halftime before Tongan prop Siegfried Fisiihoi scored an early second half try to give the home side a 10-3 advantage.
However, Leone Nakarawa crossed for the visitors with Ben Volavola converting and slotting two further penalties to give Fiji the four points to qualify with a game to spare.
Qualification was decided over results from the Pacific Nations Cup from 2016 and 2017.
The Fijians won both of their games last year, beating Tonga 23-18 and Samoa 26-16 in Suva to notch up eight points.
Samoa beat Tonga 30-10 last year in Apia, while Tonga beat the Samoans 30-26 last week in Nuku'alofa to give both teams five points from three games.
Fiji travel to Samoa next week for the final game of the tournament where the second Oceania spot will be decided.
The second-placed side will join England, France, Argentina and the United States in Pool C.
The third-placed team then face a playoff against a European side, with the loser of that game entering the repechage tournament.
(Reporting by Greg Stutchbury in Auckland; Editing by Peter Rutherford)