On a Friday night in June, Ulan Bator's only gay bar is a dark building in a sea of dark buildings. Its shades are drawn, its door shut tightly. But inside, the 100% Bar is flush with joie de vivre. Tall Mongolian men in designer shirts stand with their arms around one another, blowing clouds of cigarette smoke. A rainbow flag mingles with the vodka bottles behind the bar.

Mongolia, a traditionally pastoral country of 2.7 million people sandwiched between Russia and China, is a tough place to be gay. Homosexuality was considered taboo from the 1920s until 1990, when the country was under Soviet rule. Before 2002, it was technically illegal.

But over the past few years, a small group of human rights activists in Ulan Bator have braved ostracism, intimidation and violence to forge a gay community. In 2009 they established Mongolia's first gay rights organisation – the Lesbian, Gay, Bisexual and Transgender Centre. They have engineered a high-profile media campaign on Mongolian TV and pushed for anti-discrimination legislation in parliament. "Basically, the situation is improving there," said Robyn Garner, a co-founder of the LGBT Centre, who now lives in the Philippines. "But it's still a dangerous place to be LGBT."

Mongolia's recent discovery of vast mineral deposits has sent its economy into overdrive. Expensive bars and restaurants have blossomed among the capital city's Soviet apartment blocks and narrow, rubble-strewn alleyways.But an influx of foreign capital has also stirred a rise in ultra-nationalist neo-Nazi groups who believe in using violence to keep foreign influence at bay. Their shadow lies over the city, in the swastikas graffitied on the walls of tenement buildings and in gangs of bald, leather-clad men who prowl the streets at night.

Many gay Mongolians live in fear of these groups. In 2009, an ultra-nationalist gang beat and raped three transgender women on the outskirts of the city. LGBT Centre staff members have experienced death threats and attempted abductions. "It was only by the grace of God that we managed to escape," said Garner.

Although Ulan Bator's LGBT community is growing quickly, activists say that the country's legacy of Soviet intolerance has been hard to shake. "The majority of the public believes that being gay is just imitating cool foreigners," said Otgonbaatar Tsedendemberel, the centre's current executive director. Tsedendemberel, 32, said that in the Mongolian countryside – an endless expanse of grassland and desert where almost 40% of the population live in felt-lined tents – young men were under intense pressure to marry and have children by the age of 25. Many gay Mongolian men fear that their parents will view their homosexuality as a betrayal.

His first attempts to register the organisation, in 2007, were fraught with bureaucratic snags. The authorities banned him from using foreign terms in the organisation's title, but the words lesbian, gay, bisexual and transgender do not exist in Mongolian. Academics at the Mongolian Academy of Science denied his request to add them to the lexicon.

In November 2009, after three years of fighting, the group caught the attention of the president's human rights adviser. One month later, the request was approved. "Mongolians have a saying that it's not yet time, and when the time comes things will happen," said Anaraa Nyamdorj, a 35-year-old transgender man who manages the 100% Bar and helped found the LGBT Centre. "They don't realise that unless you make sure that the time comes, the time will never come."

One night in February, Nyamdorj's sister's ex-boyfriend walked into the 100% Bar, shouted "So you're a man now!" and punched him in the face, fracturing his eye socket.

Despite the violence, Nyamdorj has found a few unlikely allies. That night, he staggered to the police station with Tsedendemberel and found an officer who regularly patrolled by the bar. The policeman recognised Nyamdorj immediately, and after expressing concern, asked him politely if Tsedendemberel was his boyfriend.

"Just because I'm a dude and I'm there with a friend, he just assumed that I was gay," Nyamdorj said with a laugh. "I said, 'OK that's really sweet.'"