HELSINKI (AP) - Latvian lawmakers on Wednesday picked the country's long-serving and popular foreign minister, a strong backer of Ukraine, as its new head of state in a tight vote.

The 100-seat Saeima legislature elected Edgars Rinkevics, the country's top diplomat since 2011, as president to serve for a four-year term. He received 52 votes, one vote more than required to win. Incumbent Egils Levits, Latvia's head of state since 2019, didn't seek reelection.

Rinkevics, who announced in 2014 that he is “proudly” homosexual, will be the first openly gay president in the Baltic nations - all former Soviet republics where attitudes to sexual minorities have been less tolerant than in western Europe.

His closest rival, businessman Uldis Pilens, got 25 votes in the third round of voting between the two remaining contenders after the third candidate, Elina Pinto, had dropped out of the contest.

After the vote, Rinkevics tweeted that he was “honored and humbled” by the Parliament's decision and pledged “to serve the people of Latvia well.”

Rinkevics, 49, served - among other posts - as a state secretary with the Defense Ministry and worked as a journalist with Latvian Radio in the 1990s. As foreign minister, he has enjoyed high popularity among Latvians because of his hard stance toward neighboring Russia and his unwavering support for Ukraine.

In a news conference later Wednesday, Rinkevics urged countries to give Ukraine hopeful signals of a possibility of NATO membership in the military alliance's upcoming summit in Vilnius, Lithuania, in July.

Levits had been expected to seek reelection. But in a surprise move announced earlier this month, Levits said he was disappointed that parties in Prime Minister Krisjanis Karins' three-party coalition government hadn't been able to agree on a joint candidate, and said he wouldn't run in such a situation.

Latvia's presidency is largely a ceremonial post and the head of state acts mainly as an opinion leader and uniting figure in the country where almost one-third of residents speak Russian. Rinkevics ran as the candidate of his and Karins' New Unity party.

A Baltic nation of 1.9 million, Latvia borders Russia to the east, Estonia to the north and Lithuania to the south. Latvia has been a member of NATO and the European Union since 2004. The country is home to a sizable ethnic Russian minority, many of whom are Russian citizens.

Latvia regained its independence in 1991 following nearly 50 years of Soviet rule. The new president will be Latvia's 11th head of state, counting from the country's first independence declared in 1918.

The president represents Latvia abroad, acts as the supreme commander of the armed forces, signs bills into law, nominates the prime minister and has the right to dissolve the Parliament, among other things.

Rinkevics is due to be inaugurated on July 8.