Slovakia has changed its constitution, enshrining into law recognition of only two sexes – male and female,
BBC reports.
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 control 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 will 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.
"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," Beata Balagova, editor-in-chief of Slovak daily SME, told the BBC.
"Fico does not genuinely care about gender issues, the ban on surrogate motherhood, or even adoptions by LGBTQ people," she added.