Bangladeshi security officials have arrested a suspect in the killing of an American writer who was a prominent critic of extremist Islam and was hacked to death last week as he walked with his wife in Dhaka.

The arrest of Farabi Shafiur Rahman comes four days after attackers wielding meat cleavers killed Avijit Roy, an outspoken atheist and critic of the intertwining of religion and politics, on a crowded pavement in the capital, said Mufti Mahmud Khan, a spokesman for the anti-crime Rapid Action Battalion.

Mr Roy, a Bangladesh-born engineer with American citizenship, was killed on a visit from Georgia in the United States to attend Dhaka's main book fair. He and his wife, Rafida Ahmed, were attacked after leaving the fair. Ms Ahmed was seriously injured.

Rahman, a Muslim blogger who denounced atheism, had threatened Mr Roy in Facebook postings, Mr Khan said, quoting him as writing: "Avijit Roy lives in America, so it's not possible to kill him right now. But he will be killed when he comes back."

Rahman had been arrested previously for threatening an imam who performed funeral prayers for another atheist Bangladeshi blogger killed in 2013. He was released on bail after six months in jail.

While Rahman acknowledged making the threats, Mr Khan said, authorities refused to say if they believed he was one of the attackers.

"He has admitted that he threatened Avijit but we are not sharing more information with you for the sake of the investigation. We need to ask him more," Mr Khan said.

The Bangladesh government has accepted a US offer of FBI help in the investigation of the killing, according to foreign minister AH Mahmood Ali.