The Rebels wing was hauled down just short of the line after making 40 metres but he rolled over to score and Vunga Lilo added the conversion.
Namibia's tackling was leaving a lot to be desired and it was almost non-existent as Ram raced through unattended from 20 metres after the Tongans had secured clean line-out ball.
It was looking ominous for Namibia, especially with their scrum in such disorder, but a restart charge down ended with wing Russell van Wyk held up inches out before the Tongan line was breached.
Tjuiee Uanivi made good ground after Tonga lost possession and the second-row slipped the ball to wing Trump, who scorched over to the delight of the Sandy Park crowd and provide Theuns Lotze with a simple conversion.
Namibia attempted to put width on the game whenever they could but Tonga's forward supremacy gave them a powerful platform and more quick set-piece ball brought a third try.
Prop Soane Tonga'uiha peeled off the front of a line-out and second-row forwards Hale T-Pole and Joe Tuineau both helped to recycle ball for Fosita, who scored following a smart pick-up off his bootlaces.
Lilo added another penalty for a 22-7 lead but Tonga were denied a bonus point before half-time when the outstretched Veainu put his left hand on the touchline when grounding the ball with his right.
But the fourth try came within five minutes of the restart when Veainu's weaving run punished a sloppy Namibian kick and Ram coasted in for his second try.
Namibia were in danger of being blown away but they were handed a lifeline when Burger was adjudged to have touched down under a pile of bodies and Kotze added the extras from the touchline.
Tonga responded when Veainu burst through again but Namibia were far from finished and found a second wind in the final quarter.
Namibia's forward drove a maul to the Tongan line 12 minutes from time and Burger was again at the bottom of it to claim his second try.
That raised hopes of a sensational Namibia victory, but replacement Kurt Morath eased Tongan fears of lightning striking twice when he became his country's greatest points scorer with a late penalty.