Two episodes in the first week of June starkly illustrate both the promise of Indian foreign policy and the pitfalls it faces as a result of the country's increasingly toxic domestic political culture.

The promise lies in a response by India's foreign minister, Subrahmanyam Jaishankar, to a question posed by an interviewer at the GLOBSEC 2022 forum in Bratislava, Slovakia, which focused on the Ukraine war. Jaishankar's response resonated so powerfully that it quickly went viral, not just in India, but also in Europe and many other countries.

The interview with Jaishankar focused on India's continuing reluctance to choose sides in the war. India has refused to condemn Russia's invasion, while at the same time sending humanitarian aid to Ukraine and maintaining good relations with the United States both bilaterally and in the Quad.

But Jaishankar pushed back strongly against European assumptions that other countries should support their point of view on the conflict. "Europe has to grow out of the mindset that Europe's problems are the world's problems, but the world's problems are not Europe's problems," he said, adding that the world "cannot be [as] Eurocentric as it used to be in the past." India, he continued, would do exactly what Western countries do – evaluate a situation in the light of its own interests. Those interests, he emphasised, justified India's current stance on the war.

It was a clear, confident, and defiant assertion of India's strategic autonomy, and it played well at home, except perhaps with the few of us who believe that the country's strategic interests warrant a tilt towards the West in its growing confrontation with China and Russia. What was striking, too, was the way that Jaishankar's comments impressed some Muslim countries that themselves resent Western tutelage.

But no sooner had the applause for India's forthrightness echoed around the developing world than news hit of an entirely unwelcome kind of Indian outspokenness – offensive statements about the Prophet Muhammad by two of the principal spokespersons of the ruling Bharatiya Janata Party. Muslim-baiting has become standard for the Hindu-chauvinist BJP, which gains votes by stoking Islamophobia among the Hindu majority.

This time, however, the attacks went too far, crossing all acceptable limits by demeaning the Prophet himself. The internet long ago rendered obsolete the myopic assumption that India's political debates, conducted in Hindi, will affect only domestic Hindi-speaking television audiences. It did not take long for Muslim countries to erupt in fury.

Nine Muslim countries, summoned India's envoys in their capitals, dressed them down for the "unacceptable" statements, and demanded punishment for those who made them. Qatar cancelled a formal lunch for the visiting Indian vice-president. The Organisation of Islamic Cooperation capitalised on the moment by condemning it and calling on the UN to take action against it. Movements to boycott Indian goods erupted in several Muslim countries, and some Indians working in the Gulf had their employment terminated.

Indian officials scrambled to contain the damage, assuring the Muslim world that the offensive statements in no way represented the view of the Indian government but had been made by "fringe elements." The two BJP spokespersons were summarily removed from their positions, with one being suspended from the party and the other expelled. But the incident highlighted the Islamophobia unleashed or condoned by Prime Minister Narendra Modi's government, and the extensive damage it has caused to India's standing in the Muslim world.

The backlash from the Islamic world, and India's rapid response to it, served as a reminder that the Gulf region remains vital to the country's interests. It is a key trade partner, an indispensable contributor to India's energy security, a host to eight million Indian expatriate workers whose remittances support their families back home, and a significant security partner in the fight against terrorism.

For the BJP to jeopardise all of this for the sake of its vindictive, self-serving Muslim-bashing is profoundly irresponsible. Ironically, the Modi government had invested considerable effort in strengthening relations with Muslim countries, especially in the Gulf, and thus increased their salience in Indian foreign policy.

India had long enjoyed a reputation for being hospitable to Muslim interests, celebrating its diversity, and embracing its own substantial Muslim population with pride. It was India's established record, and its domestic traditions of coexistence, that made Muslim countries all the more receptive to its efforts to improve relations, despite the hostility of Pakistan.

But now a government that should know better has allowed the BJP to give free rein to its loudest chauvinist voices. When perceived domestic political interests undermine clear national interests, the country obviously should come first. Perhaps Jaishankar should direct some of his plain speaking to his own political leadership, before all his work abroad is undone by his party colleagues at home.

Shashi Tharoor, a former UN under-secretary-general, is an MP for the Indian National Congress