India's opposition Congress Party Leader Rahul Gandhi arriving at a court in Surat, India. [AP]

An Indian court found opposition leader Rahul Gandhi guilty of defamation Thursday over his remarks about Prime Minister Narendra Modi's surname and sentenced him to two years in prison.

The case against Gandhi dates back to an election rally in 2019 where he said, "Why do all thieves have Modi as their surname?" In his speech, he then went on to name fugitive Indian diamond tycoon Nirav Modi, banned Indian Premier League boss Lalit Modi, and Narendra Modi.

Narendra Modi is not related to either of the other two.

The defamation case against Gandhi was filed by a leader of the ruling Bharatiya Janata Party in western Gujarat state. The complainant, Purnesh Modi, said Gandhi's comments had "defamed the entire Modi community."

Modi is a common last name in western Gujarat state.

Gandhi, who was present in the court when the verdict was announced, said his remarks were meant to highlight corruption and were not directed against any community. He won't go to jail immediately as the court granted bail for 30 days to file an appeal against the verdict.

Mallikarjun Kharge, president of Gandhi's Congress Party, said Gandhi would appeal against the verdict in a higher court and called Modi's government "cowardly and dictatorial."

After the verdict, Gandhi wrote on Twitter: "My religion is based on truth and non-violence. Truth is my God, and non-violence the means to get it."

Gandhi, a lawmaker, is one of the main opposition leaders in India. He will most likely go up against Modi when he seeks his third term as prime minister in 2024.