“The thing about the greased piglet is that he manages to slip through other people’s hands where mere mortals fail.” That was the optimistic assessment of Boris Johnson’s chances of getting his Brexit deal through parliament by former prime minister David Cameron on Thursday.

Cameron said he would back the deal, were he still an MP, though he would have preferred one that guaranteed a closer relationship with the EU and that would keep the UK within the customs union.

During a talk to promote his book, For The Record, in North Yorkshire on Thursday evening that was repeatedly interrupted by protesters, he called on the current crop of parliamentarians to get behind the deal.

“The country voted to leave the European Union, the best way to leave is with a deal, I think a no-deal Brexit would be bad for the economy and bad for the union.

“I think it’s much better to leave with a deal, and I think Boris has done well to achieve that deal. I hope he’ll get it through parliament, I suspect he will but it will be tight.”

Cameron was asked about his relationship with Johnson and whether they had nicknames for one another. The former Tory leader said a friend had texted him earlier on Thursday to ask if the new Brexit deal would be voted through parliament, then introduced his greased pig analogy by way of response. Johnson referred to Cameron as a “girly swot” in papers discussing the prorogation of parliament, leaked documents showed.

Fielding questions from the BBC’s James Landale, Cameron said: “At the end of the day, I think this is quite close to what was talked about in the 2017 manifesto, and it is a way of leaving with a deal, so I think that is the right thing to do.

“We can’t go on being stuck. You can’t rule out having a general election if parliament cannot pass this deal and is still stuck, and you cannot rule out a second referendum.”

Cameron was speaking at Harrogate’s Crown hotel on the first night of the town’s literature festival.

In his book Cameron writes that Johnson “didn’t believe” in Brexit, but backed the leave campaign to further his career. Johnson wanted to become the “darling of the party” and “didn’t want to risk allowing someone else with a high profile – Michael Gove in particular – to win that crown”, Cameron claims.

A small group of protesters had formed outside the hotel prior to Cameron’s talk and he was repeatedly interrupted during the event.

At one stage, as he discussed the reasons for calling the 2016 EU referendum, a woman stood up and shouted: “I think the good people of Harrogate came here to hear an apology from you.”

As other audience members responded with a mixture of angry boos and applause, a man called out: “Apologise for ruining our country.” It came after Cameron had described the three years following the referendum as “very painful for the country”.

While he was discussing ways to unite the country following the division of the referendum, another man interrupted and shouted: “Your policy of austerity did absolutely nothing to bring this country together.”