A Bangladesh-based militant faction linked to al-Qaeda claimed responsibility Tuesday for hacking to death two men, one of whom was a gay rights activist and employee for a U.S. government aid program.

The attack Monday was part of a string of ambush-style slayings in Bangladesh in recent years targeting activists, journalists and others denounced by Islamist extremists for perceived liberal or Western views.

A statement from the militant group Ansar al-Islam said it killed the two men — Xulhaz Mannan, editor of Bangladesh's only LGBT magazine, and his friend Tanay Mojumder — because they were “pioneers of practicing and promoting homosexuality in Bangladesh,” the Associated Press reported.

Mannan was a U.S. Agency for International Development employee who also served as an editor for the publication Roopbaan, according to the AP. The attack occurred Monday in Mannan's second-floor apartment in the country's capital, Dhaka; police said the two men were hacked to death.

"We condemn this cruel and inhumane act of violence and add our voices to all those calling to bring his cowardly attackers to justice," USAID Administrator Gayle Smith said in a statement. She described Mannan as "the kind of person willing to fight for what he believed in, someone ready to stand up for his own rights and the rights of others. A dedicated and courageous advocate for human rights, Xulhaz sought to shape a society that was more diverse and inclusive."

Islamist militants are suspected of hacking to death a leading gay rights activist and a friend at an apartment in the Bangladeshi capital of Dhaka. (Reuters)

News reports described Mojumdar as a close friend of Mannan's. A professional contact, who asked to have her name withheld, told The Washington Post that Mojumdar was a "community organizer who conducted leadership programs."

Mannan joined USAID as a project management assistant in September, after spending eight years working as a protocol specialist at the U.S. Embassy in Dhaka, according to Smith's statement.

Marcia Stephens Bloom Bernicat, the U.S. ambassador to Bangladesh, said in a separate statement that she was "devastated" by the killings.

"Xulhaz was more than a colleague to those of us fortunate to work with him at the U.S. Embassy," Bernicat said. "He was a dear friend. Our prayers are with Xulhaz, the other victim and those injured in the attack. We abhor this senseless act of violence and urge the government of Bangladesh in the strongest terms to apprehend the criminals behind these murders."

The men were killed just two days after a university professor died in a hacking attack several hundred miles away, in the city of Rajshahi. Rezaul Karim Siddique, 58, taught English at Rajshahi University and was waiting for a bus to take him to campus when he was stabbed in the neck, Sadhir Haider Chowdhury, a city police commissioner, told CNN.

Mannan's death was condemned by Champa Patel, Amesty International's South Asia director, who said Bangladeshi authorities have a legal responsibility to protect those who express their opinions bravely and without violence.

"The brutal killing ... days after a university professor was hacked to death, underscores the appalling lack of protection being afforded to a range of peaceful activists in the country,” Patel said in a statement. "There have been four deplorable killings so far this month alone. It is shocking that no one has been held to account for these horrific attacks and that almost no protection has been given to threatened members of civil society."

A close friend of Mannan's and Mojumdar's, who asked to have his name withheld because of safety concerns, told The Washington Post on Monday that both men had received death threats a few days before they were killed.

They decided to continue doing their work, a decision that wasn't surprising, the man said.

Mannan had previous opportunities to flee the country, the friend said, but he considered his work at Roopbaan too important to abandon. The magazine, the man said, had quickly turned into a platform for supporting LGBT rights in Bangladesh.

"We knew there were threats, but I never imagined that everything would turn this ugly," the man told The Post. "I always advised him to strengthen his personal security, and I can quote his exact response: 'Living in fear is the last thing I would like to accept. If something happens to me, I would consider it an accident.' "

Police say Monday's attack was no accident, but instead a coordinated effort that involved multiple assailants.

Mohammad Iqbal, an officer in charge of the Kalabagan police station, told CNN that Mannan and his friend were attacked by five or six young men who posed as couriers and pretended to deliver a package.

After gaining access to the apartment, the assailants hacked the men to death with machetes, the officer said.

Similar details about the attackers were provided by a security guard outside the apartment building who spoke to the Dhaka Tribune. The guard, identified as Mohammed Parvez, told the paper that the youths arrived at 5 p.m. Monday.

"But half an hour later, I heard shouting and shooting sound from the flat and went to look into the incident," he said. “The assailants then attacked me with knives."

Witnesses told the news agency Reuters that the attackers shouted "Allahu Akbar," or "God is great," as they fled the scene.

Police spokesman Maruf Hossain Sorder told AFP that the individuals who carried out the killings remain unidentified.

Roopbaan, the Dhaka-based LGBT magazine with which Mannan was associated, describes itself as "a platform and publication promoting human right and freedom to love in Bangladesh." On its Facebook page, it calls itself "the country's only magazine for the LGBT community."

It is a bold description considering that same-sex relationships are illegal in Bangladesh and can result in fines or lengthy prison sentences, according to AFP.

On Monday, Facebook users posted personal tributes to Mannan as well as a YouTube video from a trip abroad.

"Today in Bangladesh," Jessie Evans wrote under a photo of Mannan, "my friend Xulhaz stabbed to death for being a successful advocate for positive change. I celebrate his warmth, his life, his relationships, and his advocacy. And I weep for his country."

"He was charismatic, a born leader and a dear friend," another friend told The Post. "He got so many volunteers for Roopbaan because these volunteers just loved to be around him. He was passionate, creative, intelligent, sarcastic and cranky at times."

"But we all knew that it's a facade," the friend added.

The Dhaka Tribune reported that Roopbaan was named after a Bengali folk character symbolizing the power of love. The paper reported that the magazine received submissions from contributors and included articles, photography and first-person stories.

At the magazine's launch in 2014, its publishers wished to remain anonymous.

“We are super excited!” an editor — who was not identified — told the Tribune, calling the magazine “a major leap forward” for the country’s LGBT community.

The editor noted that the primary reason for creating the publication was to "promote love" and "the right to love."

"The audience for love is huge and that’s who this is for,” the editor added.

Brian Murphy contributed to this report, which has been updated.