At a memorial service this week outside the concert hall where Islamist extremists are suspected of carrying out a deadly terrorist attack, one of Russia’s most popular pro-Kremlin rappers warned “right-wing and far-right groups” that they must not “incite ethnic hatred.”

At a televised meeting about the attack, Russia’s top prosecutor, Igor Krasnov, pledged that his service was paying “special attention” to preventing “interethnic and interfaith conflicts.”

And when President Vladimir V. Putin made his first comments on the tragedy last weekend, he said he would not allow anyone to “sow the poisonous seeds of hatred, panic and discord in our multiethnic society.”

In the wake of the assault near Moscow that killed 139 people last Friday, there has been a recurring theme in the Kremlin’s response: a fear that the tragedy could spur ethnic strife inside Russia. While Mr. Putin and his security chiefs are accusing Ukraine — without evidence — of having helped organize the killing, the fact that the four detained suspects in the attack are from the predominantly Muslim Central Asian country of Tajikistan is stoking anti-migrant rhetoric online.

For Mr. Putin, the problem is magnified by the competing priorities of his war in Ukraine. Members of Muslim minority groups make up a significant share of the Russian soldiers fighting and dying. Migrants from Central Asia are providing much of the labor that keeps Russia’s economy running and its military supply chain humming.

But many of the most fervent supporters of Mr. Putin’s invasion are Russian nationalists whose popular, pro-war blogs on the Telegram messaging app have brimmed with xenophobia in the days since the attack.