Slovakia has changed its constitution, enshrining into law recognition of only two sexes – male and female.
The legal change, which passed in a knife-edge vote in the central European nation's parliament, also restricts adoption to married heterosexual couples and prohibits surrogate pregnancies.
The constitutional amendment was defined as enshrining sovereignty in cultural and ethical matters.
Critics including Amnesty International have warned the change will make life more difficult for LGBT people, saying it brings the country's legal system closer to Hungary's illiberal government or Vladimir Putin's Russia.
Parliament's backing of the amendment came as a surprise to observers, with even the prime minister conceding as late as Thursday it might not pass.
Robert Fico's government – a coalition of populist, leftist and nationalist parties – needed at least 90 votes in the 150-seat Slovak National Council to change the constitution, but realistically only controls 78 seats.
However, in the end, 12 opposition MPs voted with the government. The conservative Christian Democrats had long been expected to lend their support, but several members of former Prime Minister Igor Matovic's Slovakia movement added their votes at the last minute, tipping the scales.
Matovic described them as traitors.
The populist-nationalist government argued the amendment was necessary to protect what it described as traditional values.
Fico praised the vote and said his party would have a shot of liquor to celebrate their success. This isn't a little dam, or just a regular dam - this is a great dam against progressivism, he declared.
He had previously argued that what he called liberal ideology was spreading like cancer.
Slovak legal scholars say a constitutional amendment enshrining the primacy of the Slovak constitution over EU law is a direct challenge to the European Union and may lead to legal battles and potentially sanctions.
Some said the move was merely a ploy by Fico to distract attention from falling poll ratings and unpopular policies.
Beata Balagova, editor-in-chief of Slovak daily SME, stated, The Slovak constitution has fallen victim to Robert Fico's plan to dismantle the opposition and divert attention from the real problems of society, as well as the austerity measures he had to pass.
Most opposition MPs stayed away from parliament, and Progressive Slovakia, which is leading the polls, said the betrayal marked the end of any potential cooperation with Matovic and his party.
President Peter Pellegrini said he would sign the amendment, emphasizing that a constitutional majority is an important signal for unity across the political spectrum.
Fico's Smer-Social Democracy party has now strayed far from the progressive values espoused by Europe's center-left mainstream and is at risk of expulsion from the Party of European Socialists (PES) at an upcoming conference.
Fico has also faced criticism for his relations with Vladimir Putin.