It began with a rash of unusually assertive police patrols. Armed Hamas officers stopped men from sitting shirtless on the beach, broke up groups of unmarried men and women, and ordered shopkeepers not to display lingerie on mannequins in their windows.

Then came an effort to force female lawyers to abide by a more conservative dress code, and intense pressure on parents to dress their daughters more conservatively for the new school term. Last week police began enforcing a new decree banning women from riding on motorbikes.

For the first time since Hamas won Palestinian parliamentary elections nearly four years ago, the group is trying to Islamise Gazan society. In public, Hamas leaders say they are merely encouraging a social moral code, and insist they are not trying to imitate the religious police who operate in some other rigid Islamic countries. But to many it feels like a new wave of enforcement in what is already a devoutly Muslim society.

Asmaa al-Ghoul, a writer and former journalist, was one of the first to run up against the new campaign. She spent an evening with a mixed group of friends in a beachside cafe in late June. After dark, she and another female friend went swimming wearing long trousers and T-shirts. Moments after leaving the water they found themselves confronted by a group of increasingly aggressive Hamas police officers. "Where is your father? Your husband?" one officer asked her. Ghoul, 27, was told her behaviour had not been respectable. Five of her male friends were beaten and detained for several hours.

"I believe our society is secular, but some Islamic parties want to change the idea of this society to make it religious," she said. She does not wear a headscarf, a choice that is increasingly rare for women in Gaza and generally confined only to those living in the wealthier areas of Gaza City. She routinely suffers taunts from other Palestinians as she walks from her home to her favourite coffee shops. "We're just afraid to be ourselves in the street," she said. "Hamas uses Islam in the mosque to try and control people's hearts."

Gazan society has become markedly more conservative over the last decade. In part that is down to the growing influence of Islamist movements such as Hamas and others that hold even more extremist views. Palestinians here also blame Israel's tough economic blockade, which they say has prevented a free flow of ideas and debate and largely stopped Gazans travelling abroad. Violence in the conflict, they say, tends to allow conservatism to flourish.

Hamas leaders insist there is no compulsion in their new campaign. "The main tool of the campaign is awareness and education without interfering with the behaviour of individuals or forcing them," said Talib Abu Shaar, the Saudi-educated Hamas minister of endowments and religious affairs. "It doesn't mean we are going to impose Islamic sharia [law] on the community. We don't want to be like the Taliban in Gaza."

This education campaign is called fadeela or virtue, and in part consists of posters distributed across the city. Some advise young people against smoking or taking drugs. Others warn against internet pornography or satellite television: "Be careful. Watching dirty channels corrupts the family and the coming generation." That particular poster lists recommended channels: all are religious and Islamic.

Mostly the campaign focuses on what women wear. One startling poster decries the trend for young women to wear their headscarf along with tight jeans as a "satanic industry 100%". It shows a red devil holding an image of a fashionable young woman and recommends a fuller, less glamorous head covering, counselling: "The right hijab is your way to heaven."

Asked about his attitude to those few Gazan women who do not cover their hair, Abu Shaar said: "We tell them it is an essential element to being a Muslim. Wearing the headscarf is as essential as prayer."

Perhaps the greatest surprise of the campaign is the resistance it has generated. Although Gaza is socially conservative, many Palestinians object to being commanded to follow a particular social code. When the Hamas-appointed chief justice, Abdel-Raouf al-Halabi, ordered a new uniform for all lawyers, which for women meant a headscarf and a jilbab – a full-length robe – he had not counted on the temerity of the response. Nearly all of Gaza's 150 female lawyers already wear headscarves, but they challenged the ruling on the grounds that it had no basis in law. The chief justice was forced to back down.

"It was absolutely illegal," said Dina Abu Dagga, a lawyer who has covered her hair since she was at university in Cairo.

It was not the chief justice's right to change the dress code, she said. Under Palestinian law, that power rested with the lawyers' union.

"We're not against the hijab. I wear it myself," she said. "We're against imposing it and restricting our freedoms. Today you impose the hijab, but tomorrow it will be something else."

Zeinab el-Ghunaimi, one of the few female lawyers who wears no headscarf, said some women were adopting the hijab to avoid unwelcome attention in the streets or at work. "The authorities are trying to own and control women," she said. "The problem is when these restrictions are imposed on us."

The Hamas campaign was not inevitable. Hamas is a branch of the Muslim Brotherhood, a broader Islamist movement present in most Arab and Islamic countries, which generally believes in winning over supporters by encouragement and debate one mind at a time, rather than by imposing decrees from above.

But the movement has been rattled by the appearance of more extremist groups in the Gaza Strip, including one, Jund Ansar Allah, which in August seized control of a mosque in Rafah resulting in a gun battle that left more than a dozen dead. The extremists counted among their members several disgruntled former Hamas men.

Abu Shaar, the Hamas minister, said the extremists were misguided and "in a hurry to impose sharia". Hamas, he insisted, believed in "moderate Islam".

It leaves Hamas caught between conflicting pressures ‑ those in the west who want the movement to renounce violence and become part of the political process; Hamas militants who want to return to an outright armed struggle against Israel; and extremists in Gaza who want a rapid move to a rigidly Islamic society.

Essam Younis, head of the al-Mezan human rights organisation, said what Hamas wanted most of all was to be accepted internationally as the first, successful political Islamic government in the Arab world. "They want to be part of the international game, with international legitimacy," he said. "They had a chance to provide a model, to prove political Islam can rule and provide good governance and protect human rights. But so far they have failed to set this example."