Britain could temporarily separate itself from the European convention on human rights (ECHR) in order to push through emergency laws on sentencing for terrorists in the wake of the London Bridge and Streatham attacks.

Ministers want to ban convicted terrorists from being automatically released halfway through their prison term as soon as possible following Sunday’s incident in south London. It was the second case in just over two months of a freed prisoner committing further terror offences.

On Tuesday, a government spokesman did not rule out derogating from the ECHR to try to put the new laws in place and said the legislation could be introduced in the next few days.

The possible move could be the first major test of Britain’s relationship with Europe’s legal institutions on human rights following Brexit, and comes before a review the Conservative party has said it wants to carry out into the country’s human rights laws.

On whether the country derogates from the ECHR, the prime minister’s official spokesman said: “We are going to ensure that we will bring forward the necessary legislation to protect the public because that is the right thing to do.”

Asked again if the government would deviate from ECHR rulings to bring in the fast-tracked laws, he said: “As the justice secretary said, we believe that we can bring forward this legislation and we are committed to doing so.”

In his only head-on acknowledgement of the organisation’s role in UK law, he said: “We are signatories to the ECHR.”

The shadow attorney general, Shami Chakrabarti, said allowing speculation over the ECHR’s influence to continue was a ploy to give Tory party members anti-European “red meat”.

The Labour peer said: “So what are we to believe in this new Trumpian politics? And what is their motive? This is red meat to their right wing.”

There are 224 terrorist offenders in prison, four of whom are due for early release in March, according to an analysis by the Henry Jackson Society thinktank.

Three of those were due for automatic release and could be affected by the legislation. They include Mohammed Ghani from Barnet, north London, who in 2019 was sentenced to 28 months for four offences including threatening to kill police officers in a call to 999 and possessing the Isis propaganda magazine Inspire.

Another is Mohammed Zahir Khan, a corner-shop owner from Sunderland, who was sentenced for four years and six months in May 2018 for nine counts of distributing Isis propaganda via a Twitter account and calling for “death to Shia” Muslims.

The third is Mohammed Khilji from Brent, north-west London, who was jailed in June 2018 for five years on eight counts of encouraging terrorism, by sharing graphic videos of Isis beheadings and videos calling for violence against non-Muslims.

Each is currently eligible for release at the halfway point of their sentence, with the time served discounted for time on remand.

The human rights group Liberty said it believed that the government’s proposals were at risk of being struck down by a legal challenge, because they were in apparent breach of article 7 of the ECHR.

That states “No one shall be held guilty of any criminal offence on account of any act or omission which did not constitute a criminal offence under national or international law at the time when it was committed.”

Martha Spurrier, the director of the pressure group, writing in the Guardian in a forthcoming comment piece, warned: “Everyone – including convicted criminals of course – has a right to serve the prison sentence they were given when they were tried by an independent judge.”

Other legal experts said that they believed that ministers would be able to see off any legal challenge. “The new provisions are likely to survive legal challenge so long as they do not change the total sentence, but just the arrangements for how it is to be served,” said Lord Anderson, a former independent reviewer of terror legislation.

“The courts both in the UK and in Strasbourg and have been quite pragmatic about this in similar cases in the past,” he added.

The UK can choose to depart from the ECHR in limited circumstances, specifically in times of emergency, war or “threat to life of the nation” under article 15 of the ECHR.

On whether the government considers the current situation an emergency, the spokesman said: “That’s not something we have set out. We have said we believe this is a circumstance which requires emergency legislation and that is what we’re bringing forward.”

The UK derogated from article 5 of the ECHR, the right to liberty and security, during the Troubles in Northern Ireland.