From marshes and swamps to an apartment in Brooklyn: A 41-year-old man was arrested for having an alligator-like predator in his apartment, along with drug and weapons charges, police said on Thursday.

Cops found a caiman (a reptile that looks like a small alligator) Wednesday morning inside Habakkuk Tracey’s Flatbush-Ditmas Park home, where he was allegedly keeping the reptile in a tank in the living room.

Police were executing a search warrant at the time, and recovered crack cocaine in the East 21st Street apartment as well. Tracey allegedly dropped a .380 semi-automatic handgun out of the bedroom window, which cops recovered, a police source said.

Tracey was charged with criminal possession of a controlled substance, criminal possession of a weapon, criminal possession of a firearm and having a prohibited wild animal, which is a health code violation. He has 30 prior arrests in the city, the source said.

The caiman was taken to Animal Care Centers of NYC, police said.

Tracey was held in lieu of $10,000 bail at his arraignment on Thursday.