NEW DELHI — Men armed with machetes killed a secular activist at a crowded intersection in Dhaka, the Bangladeshi capital, a police official said on Thursday, the latest in a series of grisly attacks on intellectuals and bloggers who have written critically about militant Islam on social media.

Witnesses said a group of cleanshaven men surrounded Mohammad Nazim Uddin, a law student, around 8:30 p.m. on Wednesday and slashed his head, then shot him when he fell to the ground, said Syed Nurul Islam, the deputy commissioner of police for Wari, the area of Old Dhaka where the killing took place.

Mr. Uddin, 26, was an atheist who frequently expressed his views on Facebook, often posting as many as five times a day. His family had asked him to stop, fearful that the posts would make him a target, and for about four months, ending in January, he had complied, said Gulam Rabbi Chowdhury, a childhood friend.

“To tell the truth, he was always a little detached from his family; he had trouble with them because of his views on religion,” he said. “He was very outspoken. He didn’t worry about whether you were with him or not.”