An al-Qaeda affiliate has claimed the murder of a prominent gay rights activist who was hacked to death in Dhaka by men armed with guns and machetes who entered his flat pretending to be parcel couriers.

Xulhaz Mannan, along with his friend Mahbub Tony, also an activist, died on the spot from cuts to their heads, according to police. A security guard who was also attacked was rushed to hospital.

A Twitter handle that identified itself as an outlet of Ansar Al Islam said its fighters had killed the two men, calling them "the pioneers of practicing (sic) and promoting homosexuality in Bangladesh". The group has made similar claims about the deaths of other liberal activists in Bangladesh.

Mr Mannan, who worked at the US government donor agency USAID and was previously employed as a protocol officer at the US embassy in Dhaka, was one of the founding editors of Roopbaan, the country’s first LBGT magazine. Mr Tony worked as an actor.

According to Sub Inspector Ansar Ali, Mr Mannan returned home at about 5 pm with Mr Tony arriving fifteen minutes later.

"At about 5.30 pm, five to six men came to the apartment gate saying they were from a courier company with a parcel for Xulhaz," Mr Ali said.