Police found an explosive device in a Brooklyn backyard on Tuesday — and believe it could be connected to the masked gunman who sparked a wild shoot out last week on the same street, sources said.

Officers investigating the police-involved Labor Day shooting in Brownsville came upon the container wrapped in tape Tuesday afternoon on Howard Avenue near Dumont Avenue, according to law enforcement sources.

Inside the container were shrapnel fragments, that would have gone flying had the device exploded, according to the sources.

Cops believe the low-grade explosive could be linked to Bloods gang member Brandon Clayton, who was killed early Monday in a fierce firefight involving seven police officers after he shot at a patrol car.

Clayton, 29, was wearing a mask when cops on patrol near Howard and Dumont avenues tried to confront him around 2:30 a.m., NYPD Chief of Department Terence Monahan said last week.

He took off running, and then shot several times at the officers’ squad car.

A cop returned fire, and the suspect fled.

About 30 minutes later, he apparently tried to break into a backyard on Howard Avenue.

“As uniformed patrol officers gained entry to the backyard, they were fired upon numerous times and exchanged gunfire with the perpetrator,” Monahan said.

A hail of bullets flew before Clayton ultimately was taken down. He was pronounced dead at Brookdale Hospital Medical Center.

Additional reporting by Tamar Lapin