The legal proceedings against Mr. Kuznetsov were widely criticized.

Aleksei A. Navalny, Russia’s leading opposition figure — whose recent protests have attracted a young demographic akin to Mr. Kuznetsov’s fan base — said that the government needed to be confronted over any attempt to limit free speech.

Speaking on his YouTube talk show, Mr. Navalny said that the Russian state sought to silence everyone, wanting all Russians to behave like orderly schoolchildren. The lyrics Mr. Kuznetsov had recited on the car were from a song that was not so much about taking drugs as about the conditions that lead to it, he noted, saying, “This song is about poor people who use drugs because of their poor life; they are miserable and everything is awful.”

Zakhar Prilepin, a writer who made his name with a gritty novel describing the life of young soldiers in the Chechen wars and who went on to organize fighters in the separatist regions of Ukraine, wrote a screed on Facebook in support of the rapper. His post said that “pseudomusical scum who sow vulgarity and stupidity” and hang out in their dachas abroad won medals, while the respect of the young for their country was being crushed by actions like those against Mr. Kuznetsov.

“Get out of my face you ghouls,” he wrote.

In court, Mr. Kuznetsov said that he had been forced into the position of addressing his fans in the street because they had not been allowed into the concert hall and that he had felt responsible for the canceled event.

“I felt I needed to talk to them, that they needed to hear from me,” Mr. Kuznetsov told the court in a video posted by Open Russia, an opposition media group.

Two of his other concerts were canceled in a similarly abrupt, unexplained manner, he told the court. “We did not get any official documents or official reasons for that.” The jail time could cause the rapper, who was in the middle of a 15-city tour, to miss six more concerts.