A law enforcement agent accused of joining the Drug Enforcement Administration so he could act as a “double agent” for a Puerto Rican drug cartel was ordered detained Monday until his September trial.

Chicago DEA agent Fernando Gomez was denied bail by Manhattan federal Judge Jesse Furman, who said allegations that Gomez has lived double lives for decades while in law enforcement makes him a flight risk.

“It raises in my mind an extraordinary level of deviousness,” Furman said.

Gomez was arrested last month and charged with helping the Puerto Rican drug gang starting in 2006 when he was a detective with the City of Evanston Police Department in Illinois. By 2011, Gomez, 41, had joined the Chicago arm of the DEA — specifically so he could help his drug dealer pals evade prosecution, including co-conspirator Jose Martinez-Diaz, the feds said.

“This is a criminal who tricked the DEA into hiring him,” prosecutors told the judge in arguing for Gomez to be held without bail. “He knows how to evade detection. If he is released he will know how to get away.”

Gomez’s lawyer requested home detention saying the government’s evidence of a double life is weak.

“This is a man who is on a big drug cartel’s payroll and is living large? He can barely afford us!” defense lawyer Thomas Durkin told the judge.

But prosecutors argued Gomez was wealthy enough to lease a Maserati for $695 a month — and to own a boat.

Gomez pleaded not guilty. Trial was set for Sept. 9.