A homeless man confessed to fatally bludgeoning four sleeping vagrants and critically injuring a fifth during a bloody rampage through Chinatown, a prosecutor said in court on Sunday.

Randy Santos, 24, came clean when cops confronted him with evidence of the grisly attacks, Manhattan Assistant District Attorney Alfred Peterson said.

“While he was in the 5th Precinct, he was shown video of the attacks and he admitted that he was the person in the video,” Peterson said.

Peterson also revealed that the weapon Santos allegedly used – described by law enforcement sources as a 3-foot, 15-pound piece of construction metal – was “covered in blood and hair” when cops caught him carrying it over his shoulder.

Nabbing Santos likely prevented further carnage, because “the way he was walking, it looked like he was looking for more victims,” a source has said.

Peterson didn’t allege a motive for the orgy of violence shortly before 2 a.m. Saturday but noted that “all of the people were sleeping” and Santos’ actions were “unprovoked.”

Santos, whose last known address is a homeless shelter in Brooklyn, is charged with four counts of murder, one court of attempted murder and criminal possession of marijuana in the grisly attacks along East Broadway and the Bowery near Chatham Square.

Santos was blank-faced and stared straight ahead during an arraignment in Manhattan Criminal Court that lasted less than five minutes.

He was handcuffed behind his back and didn’t speak or enter a plea during his brief appearance.

Santos has a history of unprovoked violence, including a November arrest for an incident in which a man was bitten on the chest inside a single-room-occupancy building on Manhattan’s West 35th Street, sources have said.

Court-appointed defense lawyer Arnold Levine didn’t seek bail, and Judge James Clynes ordered Santos jailed pending another hearing on Friday.