John Bercow has threatened Boris Johnson that he will be prepared to rip up the parliamentary rulebook to stop any illegal attempt by the prime minister to take the UK out of the EU without a deal on 31 October.

In a direct warning to No 10, the Speaker of the House of Commons said he is prepared to allow “additional procedural creativity” if necessary to allow parliament to block Johnson from ignoring the law.

“If we come close to [Johnson ignoring the law], I would imagine parliament would want to cut off that possibility … Neither the limitations of the existing rulebook or ticking of the clock will stop it doing so,” he said, delivering the annual Bingham lecture in London. “If I have been remotely ambiguous so far, let me make myself crystal clear. The only form of Brexit that we have, whenever that might be, will be a Brexit that the House of Commons has explicitly endorsed.”

Bercow insists Johnson must obey law and ask for Brexit extension – live Read more

He also proposed a written constitution to stop “executive malpractice or fiat”, which could potentially have avoided the constitutional crisis that the UK has found itself in over Brexit.

Bercow’s dramatic intervention will be one of his last as Speaker, as he has announced that he will stand down at the end of October just two weeks after parliament is due to return from its current state of suspension.

Johnson faced yet another difficult day on Thursday as he was forced to deny having misled the Queen over his reasons for proroguing parliament, which was judged unlawful this week by a Scottish court. The full ruling of three appeal court judges was published on Thursday, in which they agreed unanimously it was to prevent proper parliamentary scrutiny of his Brexit strategy, and for no other reason.

Play Video 1:15 Boris Johnson says claims that he lied to the Queen are 'absolutely not' true - video

Lord Carloway, the Lord President, said prorogation was sought “in a clandestine manner” during a time when Downing Street knew that 75 MPs and peers were taking the government to court to block prorogation.

Speaking after an event about shipbuilding, Johnson said it was “absolutely not true” that he lied to the monarch in advising her to suspend parliament, insisting it was a decision taken to facilitate a Queen’s speech in mid-October. The prime minister, who is due to give a speech in the north of England on Friday, highlighted a differing judgment by the high court in London and said it was for the supreme court to make a final adjudication next week.

Johnson also sought to play down a row about the role of Scottish judges in ruling prorogation unlawful after the business minister, Kwasi Kwarteng, claimed “many people” thought judges were biased in relation to Brexit.

With his options narrowing, Johnson appears to be increasing efforts to secure a deal with the EU, possibly by moving more towards a watered-down form of Northern Ireland-only backstop. However, he maintains that a no-deal Brexit on 31 October is still possible and sought to minimise the significance of the Operation Yellowhammer documents published by order of parliament on Wednesday. These set out the threat of food and medicine shortages, travel disruption and public disorder in a worst-case no-deal scenario.

The prime minister has pledged to abide by the law in general but he has also said he would rather be “dead in a ditch” than ask the EU for another Brexit extension and suggested in a letter to Tory members that he is only bound by the legislation forbidding a no-deal exit on 31 October “in theory”. His top adviser, Dominic Cummings, is said to believe that the law does not make the government bound to secure a delay from the EU, but various options – such as sending a contradictory letter to Brussels – have been dismissed as illegal by experts. Iain Duncan Smith, the former Tory leader, has suggested Johnson could be a “Brexit martyr” if he holds out against requesting an extension.

In his speech Bercow lambasted the idea that Johnson could even consider ignoring legislation passed by MPs, which mandates the prime minister to seek a three-month Brexit delay if no deal is struck by mid-October.

He went on to compare any attempt by Brexit advocates to ignore the law in pursuit of what they believe to be a higher cause to “robbing a bank on the basis that the cash stolen would be donated to a charitable cause immediately afterwards”.

Scottish court ruling: what happens next in prorogation dispute? Read more

“Not obeying the law must surely be a non-starter. Period. Surely. In 2019, in modern Britain, in a parliamentary democracy, we parliamentarians, legislators, cannot in all conscience be conducting a debate as to whether adherence to the law is or is not required,” Bercow said.

“What conceivable moral force do the public’s representatives have in seeking to tackle antisocial behaviour, in seeking to prosecute the fight against knife crime and seeking to argue the state should protect itself against all sorts of nefarious illegality if we are to treat for a moment the proposition it might be in order in the name of some higher cause to disregard … It is astonishing that anyone has even tried to entertain the notion. It would be the most terrible example to set to the rest of society.”

Bercow, who is standing down after 10 years in the Speaker’s chair, said the “Brexit maelstrom” had exposed weaknesses in the country’s political framework.

“I have been a sceptic in the past about the desirability of a written constitution for the UK,” he said. “I have come to the conclusion that it’s worth establishing a royal commission or a Speaker’s conference to explore [the options].”

It should aim to ensure, he said, that the authority of the House of Commons is “never distorted by executive malpractices or fiat ... We must consider whether a written constitution is what we need.”

Three outcomes, Bercow explained, were most likely when parliament returns on 14 October: a new withdrawal agreement supported by parliament, a no-deal Brexit backed by a Commons majority, or a request by the government to Brussels for a future temporary extension of the UK’s membership of the EU.

Bercow has become a vilified figure among Brexiters who believe he has been complicit in thwarting efforts to leave the EU.

Addressing his critics, Bercow said he believed he had never bent or broken the rules of the House of Commons.

He condemned those “bigots” who conduct personal attacks on MPs. Portraying MPs such as Dominic Grieve in newspapers as “enemies of the people” is a dangerous development, he said. And using such terms as “Go back” is noxious and repellent, he added.