Tim Farron braced himself to “go down with the ship” in the final days of the general election campaign, as private Liberal Democrat polling showed his party could be left with just three seats – excluding his own.

As he prepares to step down in favour of the former business secretary Vince Cable leading the Lib Dems, Farron said he had made a conscious decision to “bet the farm” on Brexit. He said he believed he could not have handled persistent questioning about his religious beliefs any differently without “road crashing” his faith.

“Seventy-two hours before the election I was told that I could lose my seat,” he said. “I said to aides that I had bet the farm on our position on Brexit but I was content that if I went down with the ship I went down fighting – fighting for what I believe in.”

In the event, the Lib Dems ended up with 12 seats; a significant improvement on the nine they held before Theresa May called the snap poll, but well short of the significant advance he had hoped for as the party sought to capitalise on the anguish of remainers.

He made the decision to put a second Brexit referendum at the centre of his party’s strategy last summer, after a walk with a close friend upthe hill known as Benson Knott, in the Lake District. “It’s only eight seats, we’re risking everything. But for pity’s sake if we do nothing it might evaporate to absolutely nothing. Let’s bet the farm,” he recalled.

He added: “The thing I’ve probably learnt more than anything else in my two years is the importance of clarity. Maybe you can afford nuance when you’ve got 200 or 300 MPs. When you’ve got eight, you can’t. We deliberately risked everything. I thought, if we take the safe option here we might just bleed away into total irrelevance.”

Farron, an evangelical Christian, faced repeated questions about aspects of his religious faith during the campaign, in particular about gay sex and abortion.

He insisted he could not have handled those questions any differently without “road crashing” his faith, and he made the decision, two weeks into the campaign, that he would have to resign rather than cause his party more “pain” in future as his religious views were scrutinised.

“If I’m honest with you, I felt, to deal with the questions about all sorts of things, I either had to compromise my faith and say none of it matters. Which I just couldn’t do. I could have done, but that would have been a road crash of my faith. I made the choice. Essentially I couldn’t see at that stage a ‘third way’. You either crash your faith, and I’m not going to and deny what I believe. Or I cause the party just pain.”

Some Labour MPs in pro-remain constituencies who feared the Lib Dems could encroach on their support have said the perception that Farron might believe homosexual sex was a sin (something he eventually denied) had helped them with liberal voters.

Asked if he might have cost his party support, Farron said: “It didn’t feel like it. But I’m a good campaigner, I think. Talking to people, rallying the troops. And I do wonder how much of my message was lost.”

He inherited his party in the wake of the near wipeout at the 2015 general election, after the five-year coalition with the Conservatives. He now says it was a genuine risk that the Liberal Democrats could have become extinct. “There was no doubt in my mind. The likelihood was that it was either death or survival. Without wanting to overdo the gloom, that’s exactly how it was.”

Tim Farron in Bournemouth, 2015, before giving his keynote speech at conference. Photograph: Peter Nicholls/Reuters

An internal focus group report produced at the time, and seen by the Guardian, posed the questions, “how badly damaged were we after the last six years?” and, “was there a future for the Liberal Democrats in their current form?” When voters were asked what the party stood for, by far the most prevalent answers were, “don’t know”, and “nothing”.

He and his team, including his chief of staff, Paul Butters, decided to choose emotive, liberal, issues to campaign hard on, beginning with the refugee crisis, which Farron felt strongly about. “It’s about rebuilding. It’s about trying to gain relevance. Pick specific things that you think will energise your people, that create a sense of moral purpose,” he said.

He has also focused on rebuilding his party through small, local, victories. “I had a little acronym: PAWAWI – pick a ward and win it. And it was basically about getting people; it doesn’t matter where you are, pick a ward and you could win. It might mean nothing if you’re Tory or Labour. To us it’s everything. It gave us momentum,” he said.

In the event, the reckoning for Farron’s strategy came far sooner than he expected. “I was on the way to do a local election visit when [May] announced the election and I thought ‘flipping heck, we really aren’t ready’,” he said. And as the gruelling campaign went on the party’s mood darkened.

The final days on the Lib Dem battle bus had a delirious but heavy atmosphere, as fear began to mount that the party would suffer. The battle bus route suddenly swerved from covering swaths of the south-west as it was privately admitted that the chances there looked grim, and headed for Oxford, Bath and London.

The last night on the bus included a late-night drive from rural Welshpool to Solihull, where Lib Dem aides switched on the luxury coach’s disco lights and Farron led the busload of activists and journalists in raucous karaoke, singing The Whole of the Moon, by the Water Boys.

Farron said he was proud of how his tenure had had not just “bold policies” but “eye-catching stunts”, though he admitted the party had limited airtime, which had been wasted by other gaffes, including quipping “smell my spaniel” to an activist holding their dog. “Sniffing the spaniel, that might be the name of my book,” he said.

He denied he was forced out of his job against his will. Brian Paddick, the Lib Dem peer and formerly the party’s home affairs spokesperson, and David Laws, the former Lib Dem minister, had both publicly expressed doubts about his leadership.

Farron said: “Frankly, if I’d have wanted to scrap for my leadership I would have done and we’d have won. My view was that I didn’t want to go straight away, especially once we saw the result. I don’t want anyone misinterpreting this as me thinking it was something to apologise for.”

Laws, who wrote that the Lib Dem leader held “prejudiced views”, has clearly wounded Farron. “What liberalism means in practice … means defending other people’s rights, particularly when they’re in a corner,” he said of his former colleague’s denunciation.

He had spoken “a little” with people at his church as he toyed over his future, he said, before deciding the party needed to be ready to fight any snap autumn election. “And I also thought, if I knew in my heart I wasn’t going to fight another general election, it’s more honest to just go.”

Farron insisted he was proud of his achievements as leader and hoped to play a prominent role under Cable. “I am very content with what we’ve achieved, I don’t feel I have any wounds to go and lick. We’ve saved the party, we’ve done a job.”

The departing leader will not be drawn on whether he would have preferred to see a contest to appoint his successor, but called Cable “arguably the wisest person in British politics”. He does little to hide his admiration however for Cable’s deputy, Jo Swinson, whom many in the party had expected to run for the top job. Is she a future leader? “The good thing is that if there had been a contest this time round I would have had to have stayed neutral, but the one after that, you don’t have to be.”