HELSINKI (AP) — Latvian lawmakers on Wednesday chose the country’s popular foreign minister, a staunch supporter of Ukraine, as their new head of state in a close vote.

Saeima’s 100-seat legislature elected Edgars Rinkevics, the country’s top diplomat since 2011, as president for a four-year term. He received 52 votes, one more vote than needed to win. Incumbent Egils Levits, Latvia’s head of state since 2019, did not seek re-election.

Rinkevics, who announced in 2014 that he is «proudly» gay, will be the first openly gay president in the Baltic nations, all former Soviet republics where attitudes toward 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, withdrew from the race.

After the vote, Rinkevics tweeted that he was «honoured and humbled» by Parliament’s decision and vowed to «serve the people of Latvia well.»

Rinkevics, 49, served, among other positions, as Secretary of State in the Defense Ministry and worked as a journalist for Latvian Radio in the 1990s. As Foreign Minister, he has enjoyed great popularity among Latvians due to to his tough stance towards neighboring Russia and his unwavering support for Ukraine.

At a press conference later on Wednesday, Rinkevics urged countries to give Ukraine hopeful signs of the possibility of NATO membership at the military alliance’s next summit in Vilnius, Lithuania, in July.

Levits was expected to seek re-election. But in a surprise move announced earlier this month, Levits said he was disappointed that the parties in Prime Minister Krisjanis Karins’ tripartite coalition government had been unable to agree on a joint candidate, saying he would not run in such situation.

Latvia’s presidency is largely a ceremonial post, with the head of state primarily serving as an opinion leader and unifying figure in the country where nearly a third of residents speak Russian. Rinkevics ran as a candidate for his and Karins’ New Unity party.

A Baltic nation of 1.9 million, Latvia is bordered by 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 sizeable ethnic Russian minority, many of whom are Russian citizens.

Latvia regained its independence in 1991 after nearly 50 years of Soviet rule. The new president will be Latvia’s eleventh head of state, after the country’s first declared independence in 1918.

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

Rinkevics will open on July 8.