An Islamic State fighter on a street in the city of Mosul, Iraq, on June 23, 2014. (Reuters)

Omar Mateen, the man behind the worst mass shooting in U.S. history, seemed motivated by two things: a loathing of the LGBT community and an avowed admiration for the Islamic State militant group, which has inspired "lone wolf" attacks elsewhere in the United States and the world.

It remains unclear what role the methods and ideology of the group, which is based in the Middle East, played in the slaughter Mateen carried out at a gay nightclub in Orlando. Investigators say he made a 911 phone call during the attack in which he said he was avenging the bombings of Muslims in the Middle East and referenced the 2013 Boston Marathon bombings.

But if there is a clear link between the attack in Orlando and the Islamic State, it would be the most high-profile incident yet in the group's wider, relentless campaign against gays. Ever since the group came to prominence amid security vacuums in Iraq and Syria, it has set about persecuting religious minorities, women and others whose identity and lifestyle are anathema to its puritanical creed. In areas under the control of the Islamic State, its fighters have issued edicts against homosexual behavior and flashy hairstyles and promised death for anyone caught in the act of sodomy.

Across the Middle East, the LGBT community faces varying degrees of repression, both because of laws directed against its members and the wider social stigma. But under the Islamic State, things took a devastating turn.

The Islamic State's war on homosexuals is another shocking examples of the group's brutality. (TWP)

In April 2014, a video emerged of an English-speaking extremist rambling about the risk that Western education poses to Muslim youths.

“Who’s gonna teach your children?” the Islamic State fighter says. “It’s gonna be maybe a gay, maybe a drug dealer, maybe a pedophile, you know? So it’s very important for you to protect your children from these animals, from these dirty people. Allah says that they are the worst of creatures.”

In the months that followed, the militants steadily built up a catalog of atrocities against gay people living under their watch. The group released numerous videos appearing to show the execution of supposed homosexuals. OutRight Action International, which advocates for LGBT rights, has tracked more than two dozen executions of men and women charged with crimes linked to their sexual identity.

In a single day in September, the Islamic State killed nine men and a 15-year-old boy in a Syrian town who had been accused of sodomy. In January 2015, a media wing of the extremist group released images that appeared to show fighters pushing men accused of homosexuality off a building in the Iraqi city of Mosul. In July, two men suffered the same fate in the Syrian city of Palmyra, then controlled by the Islamic State. They were shoved off the roof of a hotel after an Islamic State official ruled that they must die.

"I’d prefer it if you shoot me in the head," one of the men pleaded to the militants, according to witness testimony gleaned by the Associated Press.

According to one count, the Islamic State has killed at least 16 men through this method. At least six others reportedly were stoned to death, including one man sentenced for homosexuality who had survived being pushed off a building in March.

Last year, the BBC published the testimony of a gay Iraqi man with the pseudonym Taim who had fled an area overrun by the Islamic State. He lamented the extent to which many in the communities in which he was raised cheered the Islamic State's persecution of perceived homosexuals. (The Islamic State is also known as ISIS and ISIL.) He said:

Isis are also professional when it comes to tracking gay people. They hunt them down one by one. When they capture people, they go through his phone and his contacts and Facebook friends. They are trying to track down every gay man. And it's like dominoes. If one goes, the others will be taken down too.

It's devastating to see the public reaction to the killings. Usually, when Isis posts pictures online, people sympathise with the victims — but not if they're gay. You should see the Facebook comments after they post video of the killings. It's devastating. "We hate Isis but when they do things like this, we love them. God bless you Isis." "I am against Isis but I am totally with Isis when they kill gays." "Amazing news. This is the least that gays deserve." "The most horrible crime on earth is homosexuality. Good job Isis." "The scene is ugly but they deserve it." "Those dirty people deserve Isis."

A handful of gay men who escaped the clutches of the Islamic State gave testimony at a United Nations meeting in August.

"In the Islamic State, gays are being tracked and killed all the time," said Subhi Nahas, a 28-year-old Syrian who fled via Lebanon and found sanctuary in the United States. "At the executions, hundreds of townspeople, including children, cheered jubilantly as [if] at a wedding."

In other interviews, Nahas has noted that life was difficult not just under the Islamic State, but also under the government of Syrian President Bashar al-Assad as well as a constellation of rebel groups, including some Islamist factions, which also have executed suspected homosexuals. Syrian gays are, in a sense, double refugees, exiles from a homeland racked by war, but also from communities that rarely accepted them.

"Many gays I talk to fear refugee camps," Nahas told an LGBT advocacy organization. "For them, it is the same fear as in Syria. From what I have heard, they are bullied, assaulted and raped there. Our society is homophobic, and that does not change outside of Syria’s borders."