Image copyright AFP/Getty Image caption Nigel Farage lost in Thanet South to Conservative Craig Mackinlay by almost 3,000 votes

Nigel Farage is to remain as UKIP leader after the party rejected his resignation.

Mr Farage had previously said he would stand down after failing to win a seat in last week's general election.

But the party said there was "overwhelmingly evidence" that UKIP members did not want Mr Farage to go.

Writing in the Telegraph, Mr Farage said he had been "reluctant", but decided he "owed it to the party to stay" on as leader.

UKIP won a 13% vote share in the election - some 3.8 million votes - and has one MP, Douglas Carswell, who held his Clacton seat.

Media playback is unsupported on your device Media caption UKIP's deputy leader Paul Nuttall: 'We need Nigel Farage leading our party"

It puts the party in third place behind the Conservatives and Labour in terms of share of the vote.

Mr Farage failed to gain the seat of Thanet South, losing out to Conservative candidate Craig Mackinlay.

Speaking about his defeat, he insisted he had "never felt happier", with a "weight lifted off his shoulders".

Analysis by BBC political correspondent Robin Brant

Who is more important to UKIP, Nigel Farage or Douglas Carswell?

The answer to that question came just before 16:00 BST when the party announced its ex-leader was now its leader again. Nigel Farage has been persuaded to stay on.

Technically he has managed to honour his pledge to stand down after he failed to get elected in Thanet South on Thursday.

Two things are now clear: UKIP can't countenance a post-Nigel world. He is the party's biggest asset and it thinks a big chunk of those four million votes last week were down to him.

But one senior figure has told the BBC Mr Farage's decision to stay is a "mistake" which will only undermine his reputation for straight talking.

I think it's a safe bet to say that UKIP's only MP, Douglas Carswell, will not be happy. He heaped praise on his leader this morning but he spoke about him very much in the past tense.

Party chairman Steve Crowther said the national executive committee believed the election campaign had been a "great success" and members had "unanimously" rejected Mr Farage's letter of resignation.

"He has therefore been persuaded to withdraw his resignation and remains leader of UKIP," a party statement said.

Writing in the Daily Telegraph, Mr Farage said he had initially been reluctant, but then "breathed deep, and thought for as long as I possibly had, given the meeting was ongoing".

"I decided that as much as I had earned my holidays. As much as I wanted to spend the summer fishing, walking, and of course, in the European Parliament where all hell is currently breaking loose - that I owed it to the party that got me here," he said.

He added there were "huge battles ahead", such as new EU proposals for Mediterranean migrant quotas and issues of electoral reform.

'Curtains for me'

Mr Farage had said repeatedly ahead of and during the general election campaign he had no intention of staying in the leader's job.

In his autobiography, The Purple Revolution, he wrote: "It is frankly just not credible for me to continue to lead the party without a Westminster seat.

He added: "Was I supposed to brief Ukip policy from the Westminster Arms? No - if I fail to win South Thanet, it is curtains for me. I will have to step down."

Image copyright EPA Image caption UKIP deputy chairman Suzanne Evans said she had tried to persuade Nigel Farage to stay as leader

The 51-year-old had recommended Suzanne Evans, the deputy chairman, to head the party until the leadership challenge was complete.

Suzanne Evans said she was "very pleased" Mr Farage had agreed to remain leader.

In a tweet, she wrote: "Very pleased @Nigel_Farage still at the helm. As stated previously, I tried to persuade him to stay and was never actually appointed leader!"