Michael Gove has said some terrorism offenders should be jailed indefinitely “if necessary” as the government was warned that it faces legal challenges to emergency legislation proposed in the wake of the Streatham attack.

The senior cabinet minister said “Islamist extremist terrorists” were in a different category to other offenders and must not be released until the Parole Board had deemed them safe to be on the UK’s streets.

Gove, the chancellor of the Duchy of Lancaster and a former justice secretary, told Sky News on Tuesday that offenders should be locked up indefinitely if necessary to protect the public.

“We need to be able to prove that people are no longer a danger to the public. There is a big difference between those people who are Islamist extremist terrorists and those convicted of other offences.

“If you have people in the grip of an ideology that means they want to kill innocent people in order to advance a particular religious or political view, they are a danger to society. Until they are comprehensively deradicalised and it is safe to have those people on our streets then public protection must come first.”

He said the Parole Board would “look to see whether someone is genuinely safe” before terrorist prisoners could be released, in contrast to the current system under which offenders can be released automatically halfway through a sentence.

The attacker in Streatham, Sudesh Amman, was under 24-hour surveillance by police after his automatic release midway through a sentence of three years and four months for a terrorism-related offence.

However, experts have warned that applying legislation retrospectively to people already in prison would be challenged in the courts.

Under the government plans, which would apply to both current and future offenders, prisoners who had committed terrorism offences would only be considered for release once they served two-thirds of their sentence and had undergone Parole Board risk assessments.

Amman, who was sentenced in 2018 after pleading guilty to collecting and spreading terror material, had only been out of prison for 10 days before committing Sunday’s attack. Meanwhile, Usman Khan, who killed two people in a terror attack near London Bridge last November, had been released from jail on licence in 2018, halfway into a 16-year term for terrorism offences.

Gove said the government would try to push through the emergency legislation this week. However, a former independent government reviewer of terrorism legislation, Alex Carlile, told the House of Lords on Monday that the proposals went too far.

“The decision to lengthen the sentences of people who’ve already been sentenced and therefore expected to be serving half the sentence may be in breach of the law. It’s certainly going to be challenged,” Lord Carlile later told BBC Two’s Newsnight.

“In any event, lengthening the sentence doesn’t solve the problem because those individuals are still going to have to come out of prison at some point.”

Instead, Carlile urged the government to reintroduce tougher restrictions on released prisoners through control orders which were scrapped in 2011.

Dominic Grieve QC, the former attorney general and ex-chairman of the intelligence and security committee, described the proposal as “rather problematic”. He told the Daily Telegraph: “I don’t think that retrospectively you can change the law for prisoners already in jail.”

The human rights barrister Geoffrey Robertson QC described it as “panic legislation”.

Responding to Carlile’s warning that the plans could be “in breach of law”, Gove said the new legislation would mean they were not.

Shami Chakrabarti, the shadow attorney general, indicated she was not against automatic release being replaced for those terror offenders sentenced in the future but said the “trickier question” was about those already jailed.

She told BBC Radio 4’s Today programme: “For people who are going to be convicted and sentenced in the future, I think it would be hard in principle to object to automatic release being replaced with a discretionary release in the hands of an independent parole board.

“The trickier question is … about people who’ve already been sentenced and the suggestion is when they were sentenced the judge knew they would be subject to automatic release at a certain point and now that will no longer be automatic.

“It is obviously for the government to demonstrate that they’re proposing to change the administration of the sentence, rather than the sentence itself and they’re going to have to demonstrate that to the courts.”

Asked if she would support that move, she replied: “I do not support changing people’s sentences but there is a grey area about what is the fundamental part of the sentence and what is the administration of the sentence and it’s really for the government to construct that to make it defensible in the court.”

Amman’s ex-girlfriend has said Sunday’s attack had left her “shaking, traumatised, horrified”.

The woman, who spoke on condition of anonymity, said she endured psychological trauma while going out with Amman and that she felt trapped in their relationship, which lasted less than a year.

Amman had urged his partner to murder her “disbeliever” parents and said any Muslims not supporting Islamic State were “apostates”. The disturbing details emerged in court in 2018 when Amman was jailed for possessing terrorist material.

Now in her early 20s, his ex-girlfriend told ITV News: “He never hurt me physically, but emotionally and psychologically he did.

“I felt trapped. I tried to deal with it by myself, but it affected me tremendously,” she said. “He seemed OK at first, but it quickly became apparent that things weren’t right.”