French president Emmanuel Macron has signed his controversial pension reform into law, defying three months of protests and pleas from unions not to implement the legislation.

The alterations became law on Saturday, after the text was published overnight in France’s official journal. This followed the approval on Friday by France’s highest constitutional court of the essence of the legislation, including the banner change of raising the retirement age from 62 to 64.

Unions called for mass Labor Day protests on 1 May, and some violent demonstrations erupted in several cities overnight after the verdict was announced.

The battle to implement the law has become the biggest domestic challenge of Macron’s second term, as he faced widespread popular opposition to the changes but also sliding personal popularity.

The nine-member constitutional council ruled in favour of key provisions of the reform, including raising the retirement age to 64 and extending the years of work required for a full pension, saying the legislation was in accordance with French law.

Six minor proposals were rejected, including forcing large companies to publish how many over-55s they employ, and the creation of a special contract for older workers.

The appearance of the text in France’s Official Journal – the gazette of record – means it has now been enacted into law.

“The Social Security Code is thus amended. In the first paragraph, the word: ‘sixty-two; is replaced by the word: ‘sixty-four’,” states the text, referring to the retirement age.

Thousands turned out to protest after the constitutional court approved the key elements of the pension changes Photograph: Jérôme Gilles/NurPhoto/Shutterstock

But the constitutional court’s decision could prove a pyrrhic victory for Macron, as analysts say it has come at a major personal cost for the 45-year-old.

The president’s approval ratings are near their lowest levels ever, and many voters have been outraged by his decision to ram the pensions law through parliament without a vote using a legal but controversial mechanism denounced by opponents as anti-democratic.

Polls consistently show that two out of three French people are against working a further two years.

Macron has called the change “necessary” to avoid annual pension deficits forecast to hit €13.5bn ($14.8bn) by 2030, according to government figures.

“Stay the course. That’s my motto,” Macron said Friday as he inspected Notre Dame Cathedral in Paris, four years after a devastating fire nearly destroyed the gothic monument.

The prime minister, Elisabeth Borne, tweeted that after the verdict “there are no winners or losers”.

But the leftwing Liberation daily said in its headline above a picture of a protest: “Not defeated: opponents of the reform are not going to disarm”.

Bikes, e-scooters and garbage were set on fire in the capital overnight while protests rallying hundreds erupted in other cities, including Marseille and Toulouse.

In the western city of Rennes, protesters set fire to the entrance of a police station and a conference centre. Paris police said 112 people had been arrested as of 10.30pm local time.

An estimated 380,000 people took to the streets nationwide on Thursday in the latest day of union-led action, according to the interior ministry – a small fraction of the nearly 1.3 million who demonstrated at the height of the protests in March.

Unions issued a joint statement urging Macron not to sign the legislation into law, saying the issue was “not finished”.

The general secretary of the CGT union, Sophie Binet, called for a “popular and historic tidal wave” of people on the streets to oppose the reforms on 1 May.

In a second decision on Friday, the court rejected a bid from opposition lawmakers to force a referendum on an alternative pension law that would have kept the retirement age at 62.

France lags behind most of its European neighbours, many of which have hiked the retirement age to 65 or above.

Opponents of the changes say they penalise women and unskilled workers who started their careers early and undercut the right to a long retirement.