It is not the first time the question of Iran's social mores has hit the headlines. Six young Tehranis got into trouble after their contribution to an internet phenomenon – a lip-synched dance to an innocent pop song, Happy – went viral on YouTube. They were arrested, forced to strip naked and perform squats, and then paraded on state television. This is a country in which hardline religious tradition and globally connected modernity seem to clash daily, producing scandals over everything from leggings to actors air-kissing at Cannes. The arrest of the Happy dancers is only the latest in this long-running confrontation over what is socially permissible, or in the words of the Tehran police chief, "not obnoxious" in Iran.

From the outside, this makes it look as though Iran is a society divided, a battle raging between the religious and the louche, latte-drinking westernised middle class. The reality is far more complicated. This is more a bitter contest for power among the regime's political elites than any genuine social divide.

That should be evident from President Hassan Rouhani's official Twitter feed. On Wednesday he said: "#Happiness is our people's right. We shouldn't be too hard on behaviours caused by joy." Rouhani's election last year dealt an unexpected blow to the conservatives, who had relaxed into a position of total control over the eight years of Mahmoud Ahmadinejad's tenure. Though many of their policies, particularly segregation in universities, proved deeply unpopular across the social spectrum, they pushed ahead with their vision of a religiously straitlaced, globally antagonistic Iran.

Now they are fighting back, desperate to retain their influence and sabotage the possibility of a second term for Rouhani. Because the supreme leader, Ayatollah Ali Khamenei, has backed Rouhani's nuclear diplomacy, the hardliners can't challenge the president on that front. Instead they are using their supporters in the judiciary, the security apparatus and the state media to undermine him before the electorate as being unable to deliver on his promises for social change.

Vast amounts of money are at stake, in addition to political gain. Many of these hardliners, together with allies in the Revolutionary Guards, have benefited financially from Iran's isolation. A gradual rapprochement with the west is not only politically odious to them, but threatens their financial interests, which are wrapped up in black-market trade and lucrative state contracts.

The police went after the Happy dancers, whose clip had been drawing attention on YouTube for a month, just three days after Rouhani demanded Iran abandon its paranoid digital censorship and embrace the internet. "The era of the one-sided pulpit is over," he said. The message of the Happy arrests was: if you seek to enact digital freedom, we will torment those Iranians who exercise that right. The head of the judiciary, Sadeq Larijani, declared this week that the internet was a swamp that must be cordoned off with barbed wire.

The question is whether the hardliners are pursuing this radical agenda on anyone's behalf. The vast majority of Iranians – including the traditionally pious, the merchants, the working poor – are comfortable with a healthy measure of social openness. Iran isn't Afghanistan or Saudi Arabia. Even many deeply religious young people don't believe in mandating observance for others. The children of senior officials post selfies of themselves wearing skinny jeans and heels on Facebook.

Most Iranians watch western films, hungrily consume Turkish soaps on satellite TV, and access the internet with filter-busting software. Every presidential candidate since the mid-1990s who has promised to relax social strictures has swept the board. Even Ahmadinejad, when he won roundly in 2005, scoffed at the importance of the hijab as a relevant issue during his campaign.

Through various acts of civil disobedience – from online activism to holding hands in a park or dressing fashionably – young Iranians from all social classes have shown where they stand on liberalism. Rouhani knows that, which is why he confidently tweeted in support of the Happy kids, a genuine exchange between a president and those who elected him.

The real battle is between popular politicians and an entrenched elite that is frightened by its electoral defeat. Cornered and nervous, it is striking back in any way it can.