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 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 would make life more difficult for LGBT people, saying it brings the country's legal system closer to Hungary's illiberal government or 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.

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

Prime Minister Robert 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 potential sanctions.

Some said the move was merely a ploy by Fico to distract attention from falling poll ratings and unpopular policies, according to Beata Balagova, editor-in-chief of Slovak daily SME.

Most opposition MPs stayed away from parliament, with Progressive Slovakia leading the polls and declaring the betrayal marked the end of any potential co-operation with Matovic and his party.

President Peter Pellegrini commented that the amendment signified agreement across the political spectrum and stated he would sign it.

Reports suggest that Fico's Smer-Social Democracy party will be expelled from the Party of European Socialists (PES) for deviating from progressive values.