Rahul Gandhi has resigned as the leader of India's main opposition party, saying he took responsibility for a disastrous general election performance that saw Narendra Modi sweep to victory for a second term.

Mr Gandhi had offered to resign as president of the Congress party the day after the result was announced on 23 May, but party officials had hoped to convince him to stay.

Congress won just 52 parliamentary seats in the election to the BJP's 303. The only performance worse than that in Congress's history since independence was in 2014, when it took 44 seats and Mr Gandhi was again the face of the party.

In an open letter, Mr Gandhi said it had been "an honour for me to serve the Congress Party, whose values and ideals have served as the lifeblood of our beautiful nation".

By contrast, he accused Mr Modi's ruling Hindu nationalist Bharatiya Janata Party (BJP) of launching an "attack on our country and our cherished constitution", saying: "I have no hatred or anger towards the BJP but every living cell in my body instictively resists their idea of India."

Indian General Election 2019 Show all 10 1 /10 Indian General Election 2019 Indian General Election 2019 Bharatiya Janata Party (BJP) President Amit Shah (R) welcomes Indian Prime Minister Narendra Modi (L) at BJP headquarters prior to a ceremony to thank the Union council of Ministers for their contribution in India's general election, in New Delhi on May 21, 2019 AFP/Getty Indian General Election 2019 An Indian Bharatiya Janata Party (BJP) supporter shouts slogans and holds the party flag as he celebrates on the vote results day for India's general election in New Delhi on May 23, 2019. - Prime Minister Narendra Modi looked on course on May 23 for a major victory in India's election, with early trends from the election commission showing a clear lead for his party. AFP/Getty Images Indian General Election 2019 Indian election officials count votes using electronic voting machines at a counting center for the Lok Sabha (lower house of Parliament) election, in Jammu, the winter capital of Kashmir, India, 23 May 2019. The parliamentary elections, which began on 11 April 2019, were held in seven phases throughout India and are currently being tabulated. The Lok Sabha elections were held for 542 of the 543 Lok Sabha seats, and a party or alliance needs 272 seats to form a government. EPA Indian General Election 2019 Indian supporters of Bharatiya Janata Party (BJP) dance as they celebrate on the vote results day for India's general election in Siliguri on May 23, 2019. - Prime Minister Narendra Modi looked on course on May 23 for a major victory in India's election, with early trends from the election commission showing a clear lead for his party. AFP/Getty Images Indian General Election 2019 Indian supporters and party workers of Bharatiya Janata Party (BJP) dance as they celebrate on the vote results day for India's general election in Bangalore on May 23, 2019. - Indian Prime Minister Narendra Modi looked on course on May 23 for a major victory in the world's biggest election, with early trends suggesting his Hindu nationalist party will win a bigger majority even than 2014. AFP/Getty Images Indian General Election 2019 Indian supporters and party workers of Bharatiya Janata Party (BJP) dance and hold flags as they celebrate on the vote results day for India's general election in Bangalore on May 23, 2019. - Indian Prime Minister Narendra Modi looked on course on May 23 for a major victory in the world's biggest election, with early trends suggesting his Hindu nationalist party will win a bigger majority even than 2014. AFP/Getty Images Indian General Election 2019 An Indian member of the Dravida Munnetra Kazhagam (DMK) shouts slogans and shows portraits of party president M.K. Stalin as she celebrates on the vote results day for India's general election in Chennai on May 23, 2019. - Indian Prime Minister Narendra Modi looked on course on May 23 for a major victory in the world's biggest election, with early trends suggesting his Hindu nationalist party will win a bigger majority even than 2014. AFP/Getty Images Indian General Election 2019 Bharatiya Janata Party (BJP) supporters, wearing masks dipicting Indian Prime Minister Narendra Modi, celebrate BJP's potential win in the the Lok Sabha election the Lok Sabha elections, in Amritsar, India, 23 May 2019. The Lok Sabha, the lower house of Parliament, elections, which began on 11 April 2019, is having the results tallied today. The Lok Sabha elections were held for 542 of the 543 lower house seats, and a party or alliance needs 272 seats to form a government. According to initial polling Narendra Modi could retain the position of Prime Minister along with the Bhartya Janta Party. EPA Indian General Election 2019 A Bharatiya Janata Party (BJP) supporter wears a mask dipicting Indian Prime Minister Narendra Modi as he celebrates BJP's potential win in the the Lok Sabha election the Lok Sabha elections, in Amritsar, India, 23 May 2019. The Lok Sabha, the lower house of Parliament, elections, which began on 11 April 2019, is having the results tallied today. The Lok Sabha elections were held for 542 of the 543 lower house seats, and a party or alliance needs 272 seats to form a government. According to initial polling Narendra Modi could retain the position of Prime Minister along with the Bhartya Janta Party EPA Indian General Election 2019 Bharatiya Janata Party (BJP) supporters celebrate in their party's Assam state office in Gauhati, India, Thursday, May 23, 2019. Indian Prime Minister Narendra Modi and his party have a commanding lead in early vote counting from the country's six-week general election. AP

And Mr Gandhi suggested the vote had not been "a free and fair election", saying the BJP had undermined the Indian press, judiciary and election commission. "We didn't fight a political party in the 2019 election. Rather, we fought the entire machinery of the Indian state," he said.

Mr Gandhi was the latest scion of the Nehru-Gandhi dynasty to lead Congress - a fact that was used by opponents as a criticism of the party during the 2019 campaign. His father, grandmother and great-grandfather all served as prime ministers of India.

The next leader of the party will be tasked with rebuilding a network of grassroots support that, as things stand, seems light-years away from ever competing with the ruthless election-winning machinery of the BJP.

If Congress wants to keep it in the family, Mr Gandhi's sister Priyanka Gandhi-Vadra is a popular figure who entered active politics at the start of the year. But going down that route will open up the party to continued digs like the one delivered in Mr Modi's first parliamentary address of his second term, in which he said Congress "never recognised anybody outside the [Nehru-Gandhi] family".