Boris Johnson will go to court to challenge the order from parliament to delay Brexit, the foreign secretary has revealed.

Dominic Raab insisted the government would not break the law – after MPs passed legislation requiring him to seek an Article 50 extension – but said it would not comply either.

Vowing to “test to the limit” what the new law demands, Mr Raab said: “We will look very carefully, legally at what it requires and what it doesn’t require.”

And, asked if the government would go to the courts, he pointed to the failed legal actions to stop parliament being suspended, he told Sky’s Sophy Ridge programme: “We had two legal challenges last week and we won both of those.”

The comments suggest the controversy is heading for the Supreme Court in late October, with Dominic Cummings, Mr Johnson’s key aide, believed to be convinced there is a legal way out.

Mr Raab also dismissed a warning by a former director of public prosecutions that the prime minister is heading for jail if he flouts the law as “ridiculous”.

Shami Chakrabarti, Labour’s shadow attorney general, condemned the comments, saying: “Is that what we say to our kids? Is that what we say to vulnerable kids? It's irresponsible and elitist.”

The foreign secretary also claimed the government had failed to put forward new proposals to secure a Brexit deal for fear the EU would leak them.

“What we are slightly reticent about doing, given past experience, is putting pieces of paper that will get leaked and rubbished by the other side,” he said.

It is now clear that, regardless of the law to command a request to delay Brexit, the prime minister will not ask for it at the crucial EU summit on 17 October.

Instead, if no fresh deal is agreed, he will defy the order to ensure the controversy goes before the Supreme Court – with the Halloween deadline for crashing out just days away.

On Saturday, Lord MacDonald, the ex-director of public prosecutions, said Mr Johnson would face the same punishment as any other citizen if he defied the law.

“A refusal in the face of that would amount to contempt of court which could find that person in prison,” he warned.

It was “not an extreme outcome” as it was “convention” that any individuals who refuse to “purge their contempt” are sent to prison.

Downing Street is pinning its hopes on an extraordinary new threat to sabotage the entire EU and stop it functioning, to try to force it to cave in to the UK’s demands.