A controversial film portraying prostitution in Morocco that was shunned in the Arab world has finally been shown, amid tight security, at a film festival in Tunisia. Fears of an attack by militants saw armed police and steel barriers around the cinema and each cinemagoer searched for weapons. The film, Much Loved, has provoked a storm of criticism from opponents, most of whom have yet to see it.

Director Nabil Ayouch’s portrayal of the lives of four upmarket prostitutes working for tourists and wealthy clients in Marrakech was made on a shoestring, using unknown actors and a mostly female crew.

Neither he nor the cast were ready for the firestorm it provoked after being premiered at the Cannes film festival in May. Within days, leaked excerpts had been posted online, to a furious backlash in Morocco.

Ayouch and the cast had death threats, and the Moroccan government formally banned the film, accusing the direc- tor of staining the country’s reputation. In June, the film was praised at the Toronto film festival for its unflinching appraisal of the lives of women on the margins of society, but at home a pressure group filed a lawsuit against the director. Actor Yousseff El-Idrissi, who plays a rich client in the film, told of being attacked by knife-wielding thugs.

Facebook Twitter Pinterest Nabil Ayouch best director and Loubna Abidar at a film festival in France. Photograph: Francois Durand/Getty Images

This month, the star, Loubna Abidar, was attacked and beaten in Casablanca. She posted photographs of her injuries on social media and fled to France.

The Carthage film festival is one of the biggest festivals in the Arab world. Tunisia has emerged as a bastion of liberal values in a turbulent region, the last of the so-called Arab spring states to retain its democracy. Festival director Ibrahim Letaïef said: “It is an act of resistance to make a film.”

Last Tuesday, a suicide bomber in Tunis killed 12 presidential guards as they boarded a bus to go to work. The government declared a state of emergency, imposing a nightly curfew and blocking off Habib Bourguiba, the city centre boulevard that is home to many of the festival sites.

The attack provoked a powerful reaction. Half an hour after the bomb went off, Tunisian film director Fares Naanaa took to the stage at the nearby Le Colisée cinema to break the news, and told the audience he planned to go ahead with the screening of his feature Frontiers of the Sky. The audience broke into applause and sang the Tunisian national anthem.

Much Loved had its screening on Thursday afternoon, with cinemagoers queueing to get in three hours before the start and no sign of protests. While Ayouch’s film has captured the headlines, it also heralds a cinema revolution in the Middle East. Political and social upheaval, war, terrorism and migration are provoking what some are calling a renaissance among Arab filmmakers.

“I think we are making a cultural revolution: the role of cinema is to understand from the inside what is going on,” said Layla Bouzid, whose feature, I Can Hardly Open My Eyes, tackles the subject of teenage rebellion when the opposition includes not just parents but an oppressive dictatorship.

Letaïef says a common theme among more than 600 festival entries is the portrayal of the effects of upheaval on the lives of individuals, buffeted by forces beyond their control. And the mood is often grim. “Very serious, very black, maybe because of the situation,” he says.

This upsurge in creativity is all the more remarkable given that the film industry in the region is close to non-existent. Outside its traditional centres in Cairo and Beirut, there is little in the way of finance for film-making, and editing facilities rarely extend beyond what can be done on a laptop.

Yet film-makers armed with just hand-held cameras continue to produce work, with the turbulence around them provoking a creative avalanche. “When things go wrong, it makes you feel things inside, and gives you the impetus to show what is going wrong,” said the Tunisian director Afef Ben Mahmoud. “This is why we are making art.”

Audiences in Tunisia were supportive: the terrorist attack provoked a surge in attendance to 200,000, a festival record. Being at the centre of a storm surprised Much Loved’s Ayouch, but he says he has no regrets about making a film that has left him needing bodyguards in Morocco. “I never thought it would provoke such collective hysteria,” he told French television. “But the aim of the cinema is to provoke reactions, a debate.”