Neither side owned a comfortable lead at any stage of the contest although the Gems did have their noses in front as the game entered the final minutes courtesy of a Chloe Bibby and-one.
Latvia came right back to tie the game inside the final two minutes but following a couple of cool free-throws from Jazmin Shelley, Bibby stole the inbounds pass and then dished it to Shelley who scored four points in the space of five seconds as the Gems re-took the lead.
Both teams were in the bonus from that point on and Latvia knocked down two of their free-throws before Maddison Rocci put her opponent on skates and sunk the mid-range pull-up.
After another Latvian free-throw, Bibby (seven points, seven rebounds, three assists) hit a big-time runner out of a time-out but the opposition was able to answer again which put the pressure on Australia.
With time running out, Rocci was sent to the charity stripe where she hit both and on the ensuing play, Shelley got her hand in a passing lane to cause an interception.
That finally broke the string of back-and-forth scores and the Gems secured the victory from the free-throw line courtesy of Rocci again (ten points, six rebounds, six assists, two steals).
The tense, grind-it-out style of play which the game devolved into was evident from the start as Australia held Latvia scoreless through the first three minutes while only putting two points on the board themselves.
Zitina Aokuso (two points, six rebounds) provided a spark off the bench as she and Anneli Maley (two points, ten boards) controlled the glass before Samantha Simons ended a string of misses with some quality shooting from mid-range and the perimeter.
Ezi Magbegor then put her stamp on the game, sending a shot into the stands with a ferocious rejection before becoming the focal point at the other end of the floor.
She tallied eight points and six rebounds by the main break to give the Gems a four-point edge on the back of a 16-5 run to close out the second period.
Magbegor (17 points, ten rebounds, one steal, two blocks) and Simons (ten points) kept the scoreboard ticking over in the second half as well as they both reached double-figures before Shelley (ten points) got in on the act as well from downtown.
They led by as much nine in the third term but two fouls inside the final ten seconds, including one from beyond the arc, gave Latvia the momentum as they trimmed the deficit to just three at the last change which set up a thrilling finish.
Find the box score here and watch a replay of the game vs. Latvia below
The Gems will now await the winner of Mali vs. the unbeaten Russians to find out their Quarter-Final opponent but will have a day’s rest before that clash on Friday night AEST.
Stay tuned to Basketball Australia's social media channels for information on that game as well as a link to the live-stream.
Australia's Schedule for the Under-19 Women's World Championships (all times AEST):
July 28: Quarter-Finals
July 29: Semi-Finals
July 30: Bronze and Gold medal games