Rahul Gandhi has resigned as leader of India’s main opposition Congress party, ending weeks of speculation.

In his resignation letter, which he tweeted on Thursday, he took responsibility for the party’s defeat in the recent general election.

He had already announced his intention to resign, but party leaders had hoped to change his mind.

Mr Gandhi’s father, grandmother and great grandfather were all former prime ministers.

In the letter he added that while he had no “hatred or anger” towards India’s ruling Bharatiya Janata Party (BJP), “every living cell in my body instinctively resists their idea of India” which he said was based on differences and hatred.

He also called the impartiality of the election into question, saying that “we didn’t fight a political party… we fought the entire machinery of the Indian state”.

The BJP led by Prime Minister Narendra Modi stormed to victory in the election, winning a massive mandate.

The scale of victory stunned the opposition and pundits, who were expecting a much closer race.

Mr Gandhi was also the face of Congress when it suffered its worst defeat in 2014, winning just 44 of India’s 543 seats. This year it did marginally better with 52 seats, but many still called it a “humiliating performance”.

Mr Gandhi also lost his own seat in his family constituency of Amethi in the northern state of Uttar Pradesh, though he is still a MP because he won a second seat in the southern state of Kerala.

Since it came to power, the BJP has been accused of targeting minorities and weakening state institutions under Mr Modi’s powerful leadership. It has consistently dismissed such allegations.