Shortly after midnight a white patrol van rolls out of the compound that houses the headquarters of Kuala Lumpur's religious police. Inside are eight uniformed enforcement officers, seven men and one woman, whose navy blue uniform is set off by a multi-coloured tudung, or headscarf. The mood of the team is a strange combination of joviality and religious zeal.

Officer Akmal Adzin, a cheery, moon-faced man, is leading the patrol. "We have received complaints from members of the public about offenses relating to close proximity," he tells me.

Under Malaysia's version of Sharia law, the crime of khalwat or ‘close proximity’ between unmarried, unrelated Muslim members of the opposite sex is punishable by a fine of $US750 and up to two years in prison.

The patrol's first stop is a budget hotel out in the suburb of Sungai Besi. At the reception desk, an employee obligingly prints out a list of all the Muslim hotel guests and the team ascends to the upper floors in a lift.

Their modus operandi is simple. Going from room to room, the lead officer puts his thumb over the peep-holes in the doors, knocks loudly and demands that the occupants open up. "JAKIM," he says, pronouncing the Malay acronym for the State Religious Affairs Department. Some doors swing open to reveal dishevelled men, woken from a lonely sleep. One pair of male guests refuses to answer. After half a dozen fruitless attempts, the officers persevere at the door of a room registered to a young man in his 20s. When they finally get the door ajar, the team crowds in, led by the female officer who's snapping pictures to use as evidence.

Inside the room, the young man and an unregistered occupant – a woman in her twenties – hand over their identity cards to the officer. The cards, which Malaysian citizens over the age of 12 are legally obliged to carry at all times, contain biometric data, as well as the personal information of the holder. On the cards of Muslim citizens, the word ‘Islam’ is written next to the owner's gender.

The officers allow the young woman to make herself ‘presentable’ and put on her tudung, then the couple are led separately down to the van and driven away. In the morning, they will be interviewed by an investigator, who will decide whether or not to grant them bail. In three or four months, their case will go before the Syariah Court, the courts that deal with Islamic law cases in Malaysia.

In five of Malaysia's thirteen states, it's a crime against Islamic law for a man to dress as a woman under any circumstances.

"For the good of mankind!" one of the officers assures me, in halting but enthusiastic English.

To anyone who recalls the mixture of awkwardness and excitement that surrounds youthful sexual experiences, who thinks sex – tenderness, mutual pleasure, intimacy – might be one of the nicer things that human beings do to each other, the spectacle of religious busybodies busting two young adults for being in a room alone seems like a flabbergasting piece of intrusiveness.

But this is one of the key functions of Kuala Lumpur's religious police. It's the enforcement division of a federal religious department that now receives roughly $US220 million a year from the state budget. Malaysian critics, and there are many, point out that JAKIM gets more money than the national fire and rescue service, which has four times as many employees, plus fire engines and an air division to maintain.

Over the last three decades, Islam, enshrined in Malaysia's constitution as the state religion, has become a steadily more potent and visible force. A reinvigorated religious enforcement department is just one aspect of this change. It's also evident in the more widespread use of the headscarf, a huge growth in Islamic banking, an expansion of Islamic education, and the increasing power of Sharia law.

Channel 4

A few days before the patrol raided the hotel, the Malaysian press reported that a 53-year-old and a 62-year-old partner in the northern state of Kedah had been detained for khalwat. Muslims in close proximity with non-relatives, Muslims who have extramarital sex, drink, or gamble all have reason to fear the knock of the religious police. But no one has more reason to be afraid than Malaysia's trans women.

It's one of many anomalous facts about Malaysia that this increasingly conservative, Islamic country is home to a sizeable trans community. NGOs I spoke to put the total number between 40,000 and 60,000, of which the vast majority are trans women: women who are born male, but regard themselves as female. While the community includes some successful, high-achieving individuals, Malaysia's trans women face severe discrimination – not the least of which is that, as far as much Islamic law is concerned, their identity is inherently criminal.

While the young couple in Kuala Lumpur were being processed at the head office, Officer Akmal directed the minivan to two red light districts – Chow Kit and Bukit Bintang. These areas are known for their high population of transgender sex workers.

To the trans women who work these streets, the van is as familiar as it is unwelcome. Several vanished into the entryway of a house. All that was visible of them was a flash of departing bare leg and high heel shoe. Officer Akmal explained that it was usually necessary for his officers to go undercover to catch them. "In Islam, it's prohibited, because men obviously must be men and women must behave like women, and we have to follow the rules of divine law and Sharia law," he explained.

Between 1985 and 2012, as the Malaysian government steered the country towards greater Islamisation, every one of the country's states passed religious laws against trans women. In Kuala Lumpur, the Sharia law that applies to trans women is, in Malaysian terms, relatively benign. The law states that it's an offence for a man to pose as a woman "for immoral purposes".

In five of Malaysia's thirteen states, it's a crime against Islamic law for a man to dress as a woman under any circumstances. Since there's no way for a trans woman to alter the details on their identity cards, trans women are breaking the law just for being who they are.

Channel 4

About an hour’s drive from Kuala Lumpur lies the town of Seremban, the regional capital of Negeri Sembilan, an agricultural state whose economy is dominated by rubber plantations and palm oil estates.

For $US10 a night, the ramshackle Famous Hotel offers views overlooking the square that serves as Seremban's red light district, cramped rooms with en suite bathrooms, and the constant thrum of karaoke from the warren of cheap bars and clubs that lie beneath it.

Serafina, a trans woman who gives her age as 26, has been living here for several months. She has a few clothes on a rack. A bamboo cudgel is stashed behind the door in case of unwelcome visitors. Her few possessions include a stuffed Garfield (a memento from a German ex-boyfriend), fashion magazines, books in English – a Penguin Classics version of Sinbad, a collection of short stories by Andre Dubus – a runner's up statuette from a beauty pageant, and a battered photo album.

The photograph in Serafina's album that draws my eye shows her father, a dour-looking man in the songkok hat traditionally worn by Muslim men in Malaysia. Beside him is a tousle-headed little boy of four or five. It’s Serafina.

"I always looked more like my mother," Serafina tells me. "I always wanted to do more girly things, like cooking or dressing up."

Serafina was a good student, but her formal education ended at 15 when she left home and began supporting herself doing sex work. Her mother had died and her father was unable to accept that she was transgender. Like many trans women I spoke with, she discussed the pain and danger of sex work with professional dispassion, but her rejection by her family was a still-raw wound. Serafina found it hard to mention her father without tearing up. "I miss him so much," she said.

She has spent virtually her entire adult life in this tiny nine-block grid of low-rise buildings. By day, the streets are quiet and grey. At night, the neon signs come on above the area's dingy clubs, karaoke bars, and cheap hotels. Sex workers – Chinese, Malay, Indian, some trans, some not – teeter up and down on heels in the darkness, negotiating with clients, getting in to cars. Despite the busy trade in vice, it doesn't feel unsafe. Crime syndicates keep order in the area.

Serafina is one of about a dozen trans women working here. Her colleagues include Durga, whose ebony hair and dark complexion reveal her Tamil ethnicity. Because Durga is non-Muslim, she is spared the indignity of being arrested by the religious police. But she has suffered in other ways from Islamic hostility to transgender people. Before 1995, Hindu trans women were able to change their gender on their identity cards.

Channel 4

Now, like Serafina, Durga is stuck with the discrepancy between her lived female identity and official documents which say she is a man. At job interviews, this is a major obstacle. Employers don't want to hire trans women and few trans women feel able to cut their hair and surrender their female identity in order to get work. Durga is clear about the difficulty of making a living on the street. Clients can be drunk, dishonest, violent and infected with HIV.

As I chat to Durga, a heavy-set Indian man in his fifties waits in the shadows, sitting astride a motorcycle. He is impatient for her to finish talking. Clients seem to fit no stereotype. Young men and old, married and unmarried, even, the trans women say, members of the local religious police readily pay 50 Ringgit a time for sex.

One afternoon, Serafina took me to meet her friend Zai, who lives in a small house in a predominantly Chinese suburb of the city. Zai, a skinny sad-eyed trans woman of about 50, explained that Chinese neighbours were less judgmental of her than her fellow Muslims. Zai, like many of the trans women I met, occasionally gets freelance work as a wedding planner or a make-up artist, but the mainstay of her income is sex work.

Two words on their identity cards, Islam, and lelaki, which means male, might as well be carved in stone.

Both women complained that Malaysia's recent economic downturn had hit their business; Zai grew forlorn as she spoke of the competition she faced for clients from the younger trans women in the city.

Zai breeds cats for sale and their hungry mews were audible the whole time we chatted. Her bare front room is decorated with Islamic calligraphy and a big picture of Mecca at the height of Hajj. She, like Serafina, lost touch with her family, who were chicken farmers in Kelantan, one of the most conservative regions of Malaysia. Law-makers in Kelantan voted last year to adopt the Islamic penal code called hudud. Hudud mandates the Quranic punishments of stoning for adultery and amputation for theft. Despite the law-makers enthusiasm, it has yet to be enacted.

Much of what Zai and Serafina have lived through chimes with the experiences of trans women the world over. They both experienced an early sense of disconnection from their gender at birth, a need to express their female identity. Both were sexually attracted to men, were forced to come to terms with the incomprehension and rejection of their families. Both used female hormones and cosmetic procedures to develop a more feminine appearance.

The mockery, bullying, discrimination and casual prejudice that they have faced in Malaysia would likely be familiar to trans people growing up anywhere. Countries and communities around the world are still struggling to come to terms with the possibility that gender identities might be fluid and non-binary, that a person's declared gender might better reflect their lived experience than their sexual anatomy. The debate is far from over and can still knot self-declared liberals and feminists into contradictory and intemperate positions.

But what's distinctive about Serafina and Zai's situation is that they live in a country where the government has allied itself with the intolerant certainties of religion, where a person's gender and religion are permanently fixed at birth, and where Islamic courts are given jurisdiction over people's lives. Two words on their identity cards, Islam, and lelaki, which means male, might as well be carved in stone.

Channel 4

The Religious Enforcement Office of Seremban is housed in a narrow detached building a stone's throw from the city's central mosque. In the 1960s, Sharia law was haphazardly enforced by one or two officials. Today, the enforcement unit has 30 paid officers and can draw on 70 more from the rest of the state for major raids.

Serafina knows the inside of the enforcement office fairly well. She has come here to help her friends make bail and has had her own run-ins with the religious police. In 2009, she was arrested three times. On one of these occasions, she says, she was punched in the face. On another, a van full of religious police stopped her on the sidewalk, made her take off her top in broad daylight, and fondled her breasts on the pretext of checking her identity.

Serafina tried to file a complaint with the city police, without success. But her repeated arrests came to the attention of a Malaysian human rights group called Justice for Sisters.

Serafina and three other trans women became the applicants in a legal case intended to test the constitutionality of the sharia law. The women's lawyers argued that Negeri Sembilan's rule against cross-dressing conflicted with their clients' constitutional right to freedom of expression. They also said that Serafina and her fellow-applicants were suffering from gender-identity disorder.

After a lower court ruled against them, Serafina's lawyers took the case to Malaysia's Supreme Court. One of those who helped Serafina fight the case is a trans woman called Nisha Ayub who runs a charity in Kuala Lumpur called SEED Foundation. SEED's 9,000 clients include trans women in dire poverty, some who are homeless and living with HIV.

Over cups of sweet teh tarik one hot January afternoon, Nisha explained she had many reasons for wanting the case to succeed. Nisha herself had been arrested in the state of Malacca under a cross-dressing law in 1999, when she was 21.

Despite it being a first offence, Nisha was sent to a male prison where she was sexually assaulted by the other inmates. The experience politicised her and she decided to take an active role fighting for the rights of Malaysia's trans community.

On the day I visited, a dozen trans women were eating a lunch of fish and rice in SEED's kitchen at the back of the premises, with a door for clients to come and go discreetly. One of the clients, a softly-spoken trans woman in her 60s called Ma Ipin, told me she remembered the relatively liberal climate of the 1970s, before the fatwa against gender reassignment surgery. Since then, she said, all her trans friends had either died or gone abroad.

In November 2014, Malaysia's court of appeal struck down the Negeri Sembilan law, ruling that it deprived Serafina and the other appellants of their right to live with dignity, that it contravened their constitutional rights and discriminated against individuals with gender identity disorder.

The victory took the activists by surprise. By declaring Sharia law subservient to constitutional law, it halted the decades-long encroachment of religious authority into the personal lives of Malaysia's Muslim citizens. The state government of Negeri Sembilan almost immediately sought to challenge it in the Federal Court.

Dato Haji Selamat, the head of the Islamic Affairs Department of Negeri Sembilan, has an inquisitor's penetrating stare and takes visible pleasure in the hair-splitting distinctions of Islamic jurisprudence.

"If Malaysia could speak," he told me when I visited his office, "it would say, ‘I am Muslim’."

Channel 4

He was reluctant to talk about transgender people, but he made it clear that he regarded the further Islamisation of his state as an ongoing project. He spoke approvingly of the efforts to establish hudud in the state of Kelantan and said he hoped to bring Negeri Sembilan’s punishment for drinking alcohol into line with the 80 lashes mandated by the Quran.

An official from the same department quoted the hadiths that form the basis of the Sharia law against transgender people. The hadiths – sayings and deeds attributed to the prophet Muhammad – have the status of scripture among Sunni Muslims.

"The Apostle of Allah (peace be upon him) cursed the man who dressed like a woman and the woman who dressed like a man."

But while the ruling stood, Negeri Sembilan's officers were powerless to enforce the sharia law.

One morning last September, in the days leading up to the Supreme Court verdict, Nisha Ayub left the apartment she shared with her mother. As she walked along the pavement outside her building, she was approached by two men.

"Today is your death day," one of the men announced in Tamil and struck her repeatedly with an iron bar. Nisah fell to the ground and the men ran off. When she reached hospital, she realised that the second man had slashed her from behind with a bladed weapon.

Nisha spent the night in hospital and reported the attack to the police, but no arrests have been made.

Four weeks later, on October 8, 2015, the Federal Court reversed its earlier decision in Serafina’s favour.

According to the judge, the activists had made a mistake in 2011 when they filed their original suit in a regional court; he said the suit should have been filed with the Federal Court. Serafina's legal team claimed a moral victory since the judge had ruled on a technicality, but his decision immediately restored the power of the Sharia law against cross-dressing.

A wave of arrests followed. Four days later, three trans women were arrested in Seremban. On October 15, 15 trans women were arrested in Kuala Lumpur.

Just over Northern Malaysia’s border, a five minute drive into Thailand, lies the small town of Dannok. Coming from Malaysia, you leave the province of Kedah, where the headscarf is ubiquitous and where men dressing in women's clothing can be punished under Islamic law, and arrive in a dissolute border town where seemingly anything goes.

Dannok is a kind of escape valve for Malaysians who want to party. For trans women, Thailand's tradition of tolerance towards transgender people makes Dannok a place where the ordinary rules are suspended. The struggle for survival is swapped briefly for a moment of celebration.

In a sprawling resort hotel, contestants in Miss Jumbo Diva and Miss Supermodel Diva, for plus size and skinny trans women respectively, were strutting and striking poses along a stage to pounding music.

The contestants wore sashes of various countries – Miss Congo, Miss USA, Miss South Africa – but all of them were from Malaysia. It was an opportunity for Malaysia’s trans community to let their hair down.

The room included some of the most successful members of Malaysia's trans community, many from the fashion and entertainment industries. The atmosphere was raucous and celebratory, but in deference to the sensibilities of the many Muslims at the event no alcohol was served.

The trans women were able to celebrate in the knowledge that they were safe from the religious police. But Thailand is a refuge for Malaysia's trans women in another way. In 1982, the National Fatwa Council, the highest Muslim authority in Malaysia, banned gender reassignment surgery in the country, as it was considered ‘un-Islamic’.

Today, the bulk of Malaysia's trans women travel to Thailand for surgery. Mostly this means operations to reshape the face, Adam's apple removal, and buttock and breast implants. Very few Malaysian trans women opt for the final stage of genital surgery that involves the removal of the penis.

‘Bottom surgery’, as it is known, creates a final and unresolvable contradiction between a trans woman's physical appearance and her official identity. Most Malaysian trans women who go through with it move abroad. ‘Bottom surgery’ also threatens to put an observant trans Muslim into spiritual exile. It raises questions about where she ought to worship, and who will prepare her body for burial after death.

Izan, a trans woman who runs a bridal boutique in the town of Jitra, just across the border in Kedah, was at the event to support her friend, who was competing in Miss Jumbo Malaysia. Izan is one of very few Muslim trans women who still attends her mosque every Friday. She dresses and worships as a man. Her imam knows her story and has told her that the question of her gender identity is a matter between her and God.

Izan takes hormones daily and has had a number of procedures to reshape her face and buttocks, but any further step – breast implants, penis removal – would create an insurmountable obstacle to her continued attendance at the mosque.

Channel 4

Back in Kuala Lumpur, I met Najib, a softly-spoken 29-year-old who lived for almost ten years as Nadiah, a trans woman. In 2013 he abandoned his trans identity after seeing a news report about the death of an exemplary religious young man who was mourned by his peers. Najib had been estranged from his mother and father, an Islamic scholar, since he began transitioning.

Najib went back home and told his mother of his decision to return to a male identity. He said she wept tears of joy as she cut off his long hair.

Now Najib is reunited with his parents and is studying at an Islamic seminary in Kelantan. Najib believes he can set an example for other trans women, but admits that his struggle with his sexuality is a constant jihad.

--

Over the past year, Malaysia’s ruling party has been struggling with dire economic news and a series of corruption scandals. Wary of seeming to undermine the government further, Serafina's team is reluctant to launch a fresh appeal. Meanwhile, the court's decision has left Serafina once more at the mercy of the religious police.

One recent evening, Serafina and her friend Durga waited for clients in the square on Seremban.

With a legal resolution of her problems once again so far off, Serafina speaks more often of the final genital surgery that would remove the last trace of her male identity.

Her mood varies between defiance and gloom. One moment she talks of the importance of survival and supporting her community; ‘my people’, she calls them. At another, she talks lightly of self-harm and taking her own life.

The case has also provoked a final estrangement from her father. Though she hadn't seen him for many years, they had occasionally spoken on the phone. But after Malay newspapers printed her full name in their coverage of the verdict, her father severed all contact with her.

"While I have my beauty, I can live this life," said Durga, as dusk fell. A white bindi on Durga's forehead gleamed in the streetlights. Drunken laughter broke out from a bar on the far side of square. "Everybody has a dream," said Serafina, "and I want the chance to live a second life. I want to start afresh in a country where I am accepted."