UK Independence Party leader Nigel Farage said David Cameron can only win back traditional Tory voters if he stops talking about issues such as same-sex marriage – following last night’s disastrous by-election result for the Conservatives in Eastleigh.

Tory candidate Maria Hutchings, who in comparison to the prime minister is firmly against equal marriage, came third behind UKIP’s Diane James.

Unlike the Conservatives, Labour and Liberal Democrats, UKIP is officially opposed to marriage rights for gay couples and only supports civil partnerships.

The Liberal Democrats held on to the Hampshire seat with a reduced majority of 1,771.

The party’s pro-marriage equality candidate, Mike Thornton, won despite a fall in its share of the vote of more than 14 percentage points since the 2010 general election.

“The Conservatives failed here because traditional Tory voters look at Cameron and they ask themselves ‘Is he a Conservative?’ and they conclude ‘No, he’s not’,” UKIP leader Nigel Farage told BBC Radio 4.

“He’s talking about gay marriage, wind turbines, unlimited immigration from India. He wants Turkey to join the European Union. The Conservatives’ problems are not because of UKIP, it’s because of their leader.”

But Mr Cameron dismissed UKIP’s showing as a “protest” by voters and promised to “stay true” to his principles.

He said: “It is a disappointing result for the Conservative Party, but it is clear that, in mid-term by-elections, people want to register a protest.

“But I am confident that at the general election we can win those people back by demonstrating that we are delivering for everyone who wants to work hard and wants to get on. That is what we will be focused on.”

Meanwhile, Conservative MP for Peterborough Stuart Jackson, who was among 136 Tories to vote against the Marriage (Same Sex Couples) Bill in last month’s Commons vote, published an article in today’s New Statesman titled “The Tories are suffering for gay marriage, and need to focus on migrants and a cost of living budget.”

The MP wrote: “This is the price that has to be paid for gay marriage because of the drastic unpopularity of it with activists and supporters, who have been less inclined to get out and campaign on the streets because of it. The issue has been a direct recruiting sergeant for UKIP, and there’s anecdotal evidence across the country for UKIP.”