Nicola Sturgeon is facing an urgent decision on whether to salvage an emergency bill on Brexit after the supreme court ruled the Scottish legislation was unlawful.

The court, in a significant setback for the first minister, said that key parts of a continuity bill passed by Holyrood to repatriate EU powers in areas such as farming, fisheries and policing, breached UK law. Westminster, it ruled, had the ultimate say over EU legislation.

Sturgeon now has only weeks to decide whether to amend the bill or scrap it entirely and reintroduce fresh draft legislation immediately after the Christmas and New Year holidays. Mike Russell, her constitutional affairs secretary, said he would start urgent talks with opposition parties next week.

“Time is very short indeed, not just in respect of the bill but with Brexit more fundamentally,” Sturgeon’s spokesman said. “Time is tight.”

The supreme court decision also means Scottish ministers could not embed the UN charter on fundamental rights into Scottish law, because that had been blocked by Theresa May’s Brexit legislation after Holyrood passed its emergency bill.

Senior legal sources have said that the first minister could also ask the UK government to enact many of the legal changes needed to ensure Scottish law was updated and amended at Westminster, rather than by Holyrood.

The Scottish government has already done so with nearly 50 pieces of EU law, including on GMO regulations, chemicals safety, common fisheries policy, the trade in endangered species, radioactive contamination of food, animal exports, organ transplants and the EU’s greenhouse gases trading scheme.

Leaving all the remaining powers to Westminster would involve a significant climbdown: Sturgeon insisted on introducing the legislation in February in an emergency session of the Scottish parliament after she and the then Welsh first minister, Carwyn Jones, accused May’s government of a power grab.

May insisted the UK government had the first say over how 153 EU laws and regulations would be divided up between Westminster and the devolved governments, even though many of the regulations covered powers overseen by the Welsh, Scottish and Northern Irish legislatures.

The court sparked a row between the UK and Scottish governments by confirming that much of the bill was lawful when it was introduced in March, but had since been made unlawful when the UK government changed the EU Withdrawal Act in the Lords, to further limit Holyrood’s powers.

The lord advocate, James Wolffe, told the Scottish parliament that it had affected significant swathes of the bill. Even though the Scottish Brexit bill was passed before the EU Withdrawal Act, it could not get royal assent until after the supreme court issued its ruling.

The UK government said on Thursday it had made clear what it would be doing last year, so its changes to the act were not a surprise. Russell rejected that, accusing UK ministers of “constitutional vandalism”.

However, the supreme court stated that one key part of the Scottish bill, section 17, had always been unconstitutional since it tried to override the Scotland Act which set up the Scottish parliament. That gave Westminster ultimate authority over Holyrood in some key areas.

Adam Tomkins, the Scottish Conservatives’ constitution spokesman, said the supreme court’s ruling meant the continuity bill was dead and should be withdrawn. “It eviscerates the bill, leaving it in tatters,” he told MSPs after Wolffe’s statement.

