Tim Farron, the MP for Westmorland and Lonsdale, has been named the new leader of the Liberal Democrats, winning the vote among party members by 56.5% to 43.5%.

Farron, a former party president who was one of the eight Lib Dems to retain their seats in May’s general election, beat the MP for North Norfolk, Norman Lamb, by 4,500 votes out of a total of 34,000.

The contest was triggered by the resignation of Nick Clegg, who quit the day after the party lost 48 of its 56 MPs, leaving it the fourth party in the Commons.

Voting closed at 2pm on Wednesday and the result was announced on Twitter, through the Lib Dem press office account, on Thursday, putting to an end 10 weeks of busy campaigning.

We are delighted to announce that @timfarron has been elected as Leader of the Lib Dems. http://t.co/f6SCO9cZUY pic.twitter.com/Khd7KH64aF — Liberal Democrats (@LibDems) July 16, 2015

Minutes after the result was announced, Farron tweeted his followers to thank them for their support.

THANK YOU! This is a liberal country. Our job now is to turn millions of liberals throughout the UK into Liberal Democrats #LibDemFightback — Tim Farron (@timfarron) July 16, 2015

Lamb said the leadership election had energised the party and that he gave his full backing to Farron. He said: “Tim Farron will be a passionate leader of our party, championing social justice and leading from the front in our campaign to rebuild the liberal voice in our country.”

A key figure on the left of the party, Farron was always the favourite to win the contest, polling 58% of the vote in a survey of party members conducted on Monday.

Speaking to an audience of around 500 party members after his victory, Farron described the Lib Dem defeat at the general election as “overwhelming, desperate, heartbreaking.” He said the party’s election campaign had focused too much on what the party wasn’t instead of what it was.

“So let me be crystal clear what the Liberal Democrats are for: we are the party that sees the best in people not the worst,” said Farron to deafening applause.

“We are the party that believes that the role of government is to help us to be the best that we can be, no matter who we are or what our background.”

Despite being widely respected for his campaigning on mental health, Lamb, who served as Clegg’s parliamentary private secretary and the care minister under the coalition government, struggled to shake off the image of being a continuity candidate.

Lamb won the support of many of the party’s most senior figures, including former leaders Menzies Campbell and Paddy Ashdown and the founding member of the Social Democratic party, Shirley Williams, whereas the bulk of Farron’s support came more from the grassroots of the party.

Though Farron claims to be passionately proud of the Lib Dems’ record in government, he voted against some of the coalition’s most unpopular policies, including the bedroom tax and, crucially, tuition fees – something he admits will have helped his campaign.

Farron now faces the daunting challenge of rebuilding the party, which saw its worst result since it was founded with the merger of the Liberal party and the SDP in 1988.

His approach will be to start at the very bottom. “Pick a ward and win it … There’s a small foothill, scale it,” he told the Guardian before the vote, arguing that the party will need to make big gains at local elections if it is going to stand a chance of winning back some of those 48 lost seats in 2020.

The Lib Dems under Farron will not try to be outspoken on every issue, but will instead champion issues that the two more populist parties are not willing to tackle. They will campaign against the right to buy being extended to Housing Association tenants and be unequivocal about the tragedy of the Mediterranean migrant crisis while extolling the benefits of immigration.

“If we cheese off 70% of the electorate, but 30% embrace us, we’ll have that,” he told the Guardian in an interview during the campaign.

Despite calls from Danny Alexander, the former Lib Dem chief secretary to the Treasury, for the party not to vacate the centre ground and become “a sort of soggy Syriza in sandals”, Farron has been clear that he is not a centrist politician.

“I think centrism is pointless. It’s uninspiring. I’m not a centrist,” he said at a recent hustings in Bristol, though he refused to say where he saw himself on the political spectrum, insisting politics was more complicated than left and right.

Clegg welcomed Farron’s victory, describing him as “a remarkable campaigner” and a man of “the utmost integrity and conviction” who would always have his support.

The former Lib Dem leader said in a statement: “He is a natural communicator with a rare ability to inspire people and rally them to our cause. He knows how to win and I have no doubt he can pick the party up and get us fighting again. It has been a pleasure to serve alongside Tim in parliament and a privilege to consider him a friend.”

The election – which saw the candidates take part in 25 hustings and more than 100 campaign events – was superficially civil, with both candidates professing their admiration for one another. But last month, Lamb suspended two members of his campaign team when they were found to have privately polled party members about what Lamb’s aides considered to be Farron’s illiberal voting record on abortion and LGBT rights.

Farron is a committed Christian and was among nine Lib Dem MPs who abstained at a third reading of the marriage (same-sex couples) bill, a move he attributes to concerns about aspects of the bill relating to “protecting people’s right to conscience”.

When asked to name policy areas where the two candidates differed, Lamb would cite Farron’s opposition to assisted dying, which Lamb said was fundamental to his own liberalism.

Farron told the Guardian during the campaign that he did not think he would be receiving the same level of scrutiny of his religious beliefs if he were Jewish or Muslim, and that people who were concerned his faith would affect his ability to lead a liberal party should “look more carefully into what liberalism really is”.