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 controlled 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.

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.

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.

Fico’s Smer-Social Democracy party has now strayed so far from the progressive values espoused by Europe’s center-left mainstream that reports say it will be formally expelled from the Party of European Socialists (PES) at a conference next month.