“He was very forthcoming with us,” Chief Aubry said. “He knew what he was doing when he was coming up here, and he relayed all of that information to us.”

The attack on Mr. Caughman, who was black, came as cities across the country, especially New York City, are experiencing a rise in hate crimes since the presidential election. Mayor Bill de Blasio, who has condemned the attacks, denounced the killing, which he said appeared to be based solely on Mr. Caughman’s race.

“More than an unspeakable human tragedy, this is an assault on what makes this the greatest city in the world: our inclusiveness and our diversity,” he said.

The victim, who lived in a homeless shelter on West 36th Street, and was an avid recycler, according to his Twitter profile, had been sifting through the trash around the corner on 9th Avenue, in front of a row of restaurants, when he was accosted by a man in a dark coat around 11:15 p.m. on Monday, the police said. The assailant argued with Mr. Caughman before stabbing the victim, according to the police, who declined to say what words they exchanged. After the attack, Mr. Jackson, the police said, threw the sword in a nearby garbage can and went into a restaurant restroom to wash the blood off.

Image Timothy Caughman in an image from Twitter.

Mr. Caughman walked two blocks to the Midtown South Precinct, where he arrived about 10 minutes after the attack. Officers summoned an ambulance to take him to Bellevue Hospital where Mr. Caughman was later pronounced dead.