Mayor Bill de Blasio’s office, which has struggled to address the rise in homelessness, said in a statement that it will “dedicate more resources to prevent similar tragedies in the future,” including increased police presence.

The suspect was identified as Rudy Rodriguez Santos, and he was expected to be charged on Saturday afternoon with murder, according to a law enforcement official, who spoke on the condition of anonymity to discuss an open investigation.

Mr. Santos was captured on surveillance video approaching the locations where the attacks had occurred carrying a metal bar, the official said. At least one of the attacks was also recorded by a security camera.

When investigators showed him the video, Mr. Santos identified himself in the images, but did not explicitly admit he had killed the men, the official said. Investigators repeatedly asked him why he had attacked the victims, but he refused to answer and then asked for a lawyer, the official said.

Tang Wu, the manager of the Forever Health Pharmacy at 2 East Broadway, said the security camera at his store captured one of the attacks. He said the footage shows a man with a metal bar repeatedly hitting two men who were sleeping on a piece of cardboard outside the pharmacy at 1:38 a.m. The attacker struck the men about five times, then ran off, only to return a few minutes later and continue the assault.

“They have nowhere to live and you beat the m to death,” said Mr. Wu, as he washed the blood from the pavement in front of his store with a mixture of bleach and water. “How terrible.”