A federal Drug Enforcement Administration agent in Chicago is accused of joining the force to help a dangerous Puerto Rico-based drug cartel.

Fernando Gomez, 41, faces drug, conspiracy and firearms charges. If convicted, he could serve up to life in prison, prosecutors said.

A judge on Thursday ordered that he remain in federal custody in Chicago until he is shuttled to New York to face charges there, authorities said.

Gomez allegedly became a DEA agent so that he could help members of a "narcotics conspiracy" evade the law.

Before joining the DEA, he was a police detective in Evanston, a Chicago suburb. In that job, Gomez sent firearms he obtained from drug dealers to Jose Martinez-Diaz, aka “Tony Zinc,” in Puerto Rico, according to the U.S. Attorney’s Office in the Southern District of New York.

Martinez-Diaz is a part of La Organizacion de Narcotraficantes Unidos (“La ONU”), a "racketeering enterprise involved in drug dealing and murders," according to prosecutors. He was arrested by the FBI earlier this year, the Chicago Tribune reported.

Gomez also helped Martinez-Diaz and the cartel funnel drugs to New York, according to an indictment announced on Dec. 11.

“Fernando Gomez is a special agent of the DEA, an organization committed to upholding the nation’s drug laws and relentless in its pursuit of narcotics traffickers. But as alleged, Gomez joined the DEA to betray those laws, and to help narcotics traffickers evade detection by law enforcement," said U.S. Attorney Geoffrey S. Berman.

A judge on Thursday denied Gomez's request to be released and to travel from Chicago to New York on his own. Instead, he will remain in federal custody and be shuttled to New York by U.S. marshals, said Jim Margolin, a spokesman for the U.S. Attorney's Office in Manhattan.

He is due in New York no later than Jan. 4, and his arraignment is set for Jan. 7.

NBC Chicago reported that Gomez's attorney said the accusations against his client are a "far cry" from his "good character."