Shortly after the 1979 revolution, Iran’s Islamic government banned women from a range of sporting events, most notably men’s soccer and volleyball matches. Those national teams draw massive domestic followings, and soccer club teams pack stadiums with crowds that rival the size of European counterparts.

And ever since the ban, some women have disguised themselves as men to sneak into sporting events. The half dozen that made it into Tehran’s Azadi Stadium last week wearing fake beards and mustaches to see popular club Persepolis are being hailed as national heroes on social media. And they have again highlighted the conflict between the country’s mostly secular populace, some 80 million people, and the deeply religious government.

“You will not find another country on the planet where the attitudes of the ruling class are so different than those of the regular people,” said Alex Vatanka, a senior fellow at the Middle East Institute, a nonpartisan think tank. His father played for the Iranian national soccer team before the revolution.

The stadium ban has its foundation in the Semitic tradition of female chastity and piety. Women in Iran are required to wear head coverings in public. They are allowed to watch other women play soccer, but not men.

Women and young girls are encouraged to play sports, Vatanka said, as long as they adhere to the government’s conservative laws on dress.

What’s more, the ban is enforced inconsistently. At some matches, women caught in disguise are turned away at stadium entrances. At others, they are arrested. At a World Cup qualifying match in Tehran against Syria in 2017, Syrian women were allowed to watch the game, but Iranian women, including some parliament members, were not.

One female parliamentarian threatened to call the country’s minister of sport before the national legislature for questioning.

In March, 35 women were detained trying to enter a match between Esteqlal and Persepolis with FIFA President Gianni Infantino in attendance, according to the BBC.

“Here’s Iran,” said Patrick Clawson, research director at the Washington Institute for Near East Policy, “which not only encourages women to vote and drive, but encourages them to join military units. But they can’t attend soccer games.”

Some politicians, including former president Mahmoud Ahmadinejad, have said women attending games does not violate Islamic law. He rescinded the rule in 2006.

“The best stands should be allocated to women and families in the stadiums in which national and important matches are being held,” Ahmadinejad said on state television. “The presence of women and families in public places promotes chastity.”

Supreme Leader Ayatollah Ali Khamenei reinstated the ban weeks later.

FIFA, soccer’s worldwide governing body, has long been at odds with the religious factions of the Iranian government over the ruling.

“It just seems so ad hoc, so random,” Vatanka said. “There are no hard rules. And the only sort of logic behind it is that it’s only about political control.

“If you give in on this issue, or the issue of [head coverings], what else are they going to come and ask you for? What other concessions? So when you’re done with those issues, what would be left for them to rule over?”

Iranian soccer fans last week at a different game chanted the name of Reza Shah, the country’s autocrat from 1925 to 1941 and father of the Shah deposed in 1979.

Reza Shah was certainly no democrat, Vatanka said, but he wrested control of civil society from religious clerics and led a modernization campaign that returned Iran to the world stage.

He was an Iranian nationalist who sometimes persecuted minorities, but if you stayed out of politics, Vatanka said, the Shah left you alone and didn’t care who went to soccer matches. The ayatollah’s government does care, perhaps too much.

Read more from The Post:

Dennis Rodman says he deserves some credit if North Korea summit happens

North Korea sent cheerleaders to the Olympics. Here’s what they’re saying.

John Wall wants the Wizards to overhaul their roster. They likely won’t be able to.

The banged-up Celtics aren’t as talented as the Sixers. They didn’t need to be in Game 1.

Redskins high on their draft haul: ‘The football gods were looking after us’