The alleged gunman who shot up an NYPD station house in The Bronx early Sunday has been identified by police sources as Robert Williams, a career criminal with busts including homicide.

Williams allegedly walked into the 41st Precinct headquarters on Longwood Avenue around 8 a.m. and opened fire in a wild scene caught on video, possibly hitting a lieutenant in the arm before he was taken into custody, sources said.

It’s believed Williams was also responsible for the Saturday night ambush of two cops sitting in a marked patrol van nearby, hitting one of them with a round that nearly struck his carotid artery, sources said.

Williams, who was cuffed amid the cop-shop chaos, has a lengthy and troubling rap sheet, according to NYPD insiders.

His record includes busts for homicide and gun possession — and one police source said that he was only recently released from custody for toting a piece of heavy weaponry.

“He just got out for a machine gun charge,” revealed the insider.

Williams was taken to an area hospital for injuries sustained in his brazen station-house assault, and no charges were immediately announced.