The man who police say shot at officers upstate was arrested in Brooklyn on Monday evening after a statewide manhunt, the NYPD said.

U.S. Marshals Regional Fugitive Task Force members arrested Joshua Stuart, 42, around 5:30 p.m. in Gowanus after briefly chasing after him on foot, sources said.

According to sources, Stuart tried to jump into the Gowanus Canal in an attempt to flee but police apprehended him first.

Stuart is suspected of firing shots at police in Ellenville, New York, early Friday morning.

No one was hurt in the shooting, and the motive is still unclear.

Stuart also allegedly robbed someone at gunpoint in Bay Ridge, Brooklyn around 9 a.m. before fleeing the scene.

He was previously seen in the Flatbush area of the borough. Police considered him armed and dangerous.

Charges were pending against Stuart as of this writing.