A madman went on a bloody rampage in which he fatally mowed down a pedestrian in Williamsburg, then car-jacked at least three vehicles before he was killed by a Long Island cop whom he threatened with a bat, law enforcement sources said Monday.

Michael Ward, 44, who had at least a dozen prior arrests in Virginia, traveled from Maryland to New York to start his crime spree across three boroughs and Nassau County, sources said.

Ward first punched a 77-year-old man on Melrose Avenue in the South Bronx at around 8:30 p.m. Saturday, knocking him to the ground and robbing $20, the sources said.

Early Monday morning, Ward surfaced again to steal a white Acura, which he drove to Brooklyn, and fatally struck a 50-year-old man walking across Metropolitan Avenue in Williamsburg at 3:45 a.m.

Ward fled and ended up on the Lower East Side of Manhattan at 4:30 a.m., where he swiped $20 and a Honda Odyssey from a female victim at Madison and Montgomery streets.

Just 11 minutes later, he carjacked another person driving a black Acura by punching the victim in the face on Harrison Street and taking the vehicle. He left the Odyssey behind.

Then while driving uptown, Ward sideswiped a pedestrian, sources said. It wasn’t clear what condition he left his victim in.

Ward was spotted in Jamaica Estates, Queens, shortly after by license-plate-reader technology, according to sources.

He then ended up in Great Neck, LI, where he attacked two men with a bat, sources said.

A rookie police officer attempted to subdue the crazed killer with a stun gun but was unable to contain him, sources said.

Ward refused to put down his bat, so the officer fired two shots, hitting Ward once in the chest and killing him at around 10:30 a.m., sources said.

He was driving a Volkswagen at the time of the Long Island attack, sources said.