TEHRAN — Like many teenage girls, Maedeh Hojabri liked to dance in her bedroom, record it and post clips to Instagram.

But Ms. Hojabri lives in Iran, where women are not allowed to dance, at least not in public. The 19-year-old was quietly arrested in May and her page was taken down, leaving her 600,000 followers wondering where she had gone.

The answer came last Tuesday on state television, when some of her fans recognized a blurred image of Ms. Hojabri on a show called “Wrong Path.” There she sobbingly admitted that dancing is a crime and that her family had been unaware she had videos of herself dancing in her bedroom to Western songs like “Bonbon,” by Era Istrefi.

Whatever the authorities’ intent, the public shaming of Ms. Hojabri and the arrest of others who have not been identified have created a backlash in a society already seething over a bad economy, corruption and a lack of personal freedoms.

Since Ms. Hojabri’s televised confession, scores of Iranians have posted videos of themselves dancing in protest, while thousands more have posted pictures of her and written supportive posts on their Instagram pages.

But for Iran’s hard-liners, who have regained some credibility since President Trump fulfilled their predictions by pulling out of the nuclear deal, her videos are yet another example of why Instagram, the only Western social media tool still available in Iran, should be blocked. The messaging app Telegram was closed down in April.

In a further sign of hard-liner backlash, a woman who removed her compulsory Islamic head-covering in a public protest this past February has been sentenced to two years imprisonment and 18 years of probation, she said in an Instagram post on Sunday. The woman, Shaparak Shajarizadeh, who was arrested after photos of her defiant act spread on social media, wrote that she had received a 20-year punishment “for protesting against an unjust law.”

Last week the judiciary warned that Instagram, which has 24 million users in Iran, might be closed because of its “unwanted content.” Ms. Hojabri, and other internet celebrities like her are called “antlers” by hard-liners for the way they stand out on Instagram.

But the public seems squarely on the side of Ms. Hojabri. “Really what is the result of broadcasting such confessions?” one Twitter user, Mohsen Bayatzanjani, wrote, using special software to gain access to Twitter, which is also banned in Iran. “What kind of audience would be satisfied? For whom would it serve as a lesson, seriously?”

The criticism was sharp and bold. “In this land corruption, rape or being a big thief, animal or child abuser, not having any dignity, is not a crime,” Roya Mirelmi, an actress, wrote under a picture she posted of Ms. Hojabri that got 14,133 likes. “But in my motherland, having a beautiful smile, being happy and feeling good is not only a crime but a cardinal sin.”

President Hassan Rouhani, elected in 2013 on the promise of expanding personal freedoms, has promoted social media, tried to defend Telegram and increased the speed of the internet to allow Iranians to stream video on cellphones. But now, hard-liners have set their sights on Instagram.

In April, the commander of the national police, Kamal Hadianfar, announced that “Instagram celebrities” would soon be arrested and that 51,000 Instagram pages were under police surveillance for vulgar and obscene videos.

“Instagram started out as an innocent tool, available on the internet, where people would upload photos and write some words,” said Hamidreza Taraghi, a hard-line analyst. “But the Westerners behind it gradually turned Instagram into a mischievous tool for dangerous subversive actions against the state or pornographic purposes,” he said. “Naturally we must block it.”

That Instagram should come into the cross hairs of the hard-liners is no surprise. For decades the ruling clerics, bowing to reality, have said that people are free to do as they like, but only in the privacy of their own homes.

So a balance has been maintained. In the public realm in Iran, conservative Islamic rules apply and are enforced, so women have to wear veils and are normally barred from singing or dancing. (There are exceptions, such as the dancing in the streets that followed an Iranian World Cup victory.) In the private sphere they are free to ignore the strictures.

But Instagram has brought down the walls between private and public life in Iran. All one has to do is search “#Iran” to peek right into the Iran the clerics do not want you to see: dancers, clips of the deposed shah, girls in bikinis.

Just as elsewhere in the world Iran has its share of influencers and celebrities, who attract hundreds of thousands of followers and the advertising that comes with it, some earning enough to live from it. Now, those stars would seem to be in jeopardy.

One Iranian Instagram star, known as Saman Ghasemzadeh1, has 510,000 followers who admire videos of him doing things like holding up a fluffy lap dog, showing off his abs or taking selfies with his unveiled girlfriend while wearing T-shirts with pictures of themselves printed on them. He also advertises teeth whitening products and hair extensions.

Iranian officials have grown increasingly exercised by the online behavior of their fellow citizens. In the “Wrong Path” program, a justice official said that many people online suffer from “inferiority complexes” and are only interested in getting as many likes as possible. Talking to one of those arrested, the official, Farid Najafnia, said he was shocked.

“I asked, ‘Did you have no shame, no modesty,” he said in an interview for the TV program. “‘You published publicly the most private things that should be protected by personal privacy.’ She said: ‘I recognize cyberspace as a totally private space.’ Private, in a way that for instance 8,000 people would come and ‘like it’? Is this real? Is this true?”

In 2014 six young people were arrested after making their versions of “Happy,” a video by the American singer Pharrell Williams. They were brought on state television, where they confessed and were sentenced to 90 lashes, though the punishment was never administered. One of the members of the group, Reihane Taravati, went on to become an Instagram celebrity.

The televised confession of Ms. Hojabri made Ms. Taravati relive her own experience, Ms. Taravati said. “They don’t seem to learn from what they did in the past,” she said. “Dancing is in our culture, it’s a way of showing happiness.”