The victory means that despite a loss and a draw against the other minnows in the group, the Faroe Islands, Latvia avoided the wooden spoon, finishing just above Andorra in the final classifications.
You can watch highlights of the game above (may be subject to geoblocking).
Latvia scored two goals in each half, to at least give the loyal late-night crowd at Skonto stadium something to cheer about.
Davis Ikaunieks was first to find the net after 11 minutes, which helped settle a nervous-looking home side. Valerijs Sabala scored the next two in the 19th and 59th minutes, with Igors Tarasovs adding a fourth on 63 minutes.
Despite creating more chances, no more goals were forthcoming, but the crowd was sent home with at least some sense of hope ahead of qualifying for the 2020 European Championships, which starts in March 2019, giving coach Aleksandrs Starkovs a year to build a team capable of beating more than part-timers.
Their last victory was on September 6 last year - also against Andorra.
Portugal have qualified from the group for the finals proper as expected, with Switzerland going into the play-off round for a place.
UZVARA! @EuroQualifiers turnīru noslēdzam ar uzvaru pret Andoru 4:0 (2:0). Divi vārti Šabalam, pa vieniem D.Ikauniekam un Tarasovam #LVAAND pic.twitter.com/1zLa5KvKjT— Futbola federācija (@kajbumba) October 10, 2017