Craig Mackinlay won the day with 18,837 votes, putting the Ukip leader in second place on 16,026 - a safe 5.7 per cent majority.
The eurosceptic politician had promised to resign within 10 minutes if he failed to win the seat.
"I'm a man of my word" said Farage, announcing his resignation and recommending Suzanne Evans as the next party leader. A contest will be held in September.
Farage hinted that he may still stand for re-election by the party, saying he will take the summer off and consider whether to put himself forward.
Farage said a "great weight has been lifted" following the loss.
There was an earthquake this election and it happened north of the border, it happened in Scotland. And I think what you saw were lot of voters so scared of that Labour SNP coalition that they shifted towards the Conservatives.
On a professional level I express today a degree of disappointment. On a personal level I feel an enormous weight has been lifted from my shoulders and I've never felt happier.
Comedy rival Al Murray, who earlier told the press he deserved to win, brought in 318 votes.