WHEATON, Ill. (STMW) — One of three Schaumburg police detectives accused of withholding and reselling illegal drugs they seized from dealers pleaded guilty Friday and was sentenced to 24 years in prison.

Terrence O’Brien, 47, pleaded guilty to unlawful possession of a controlled substance, official misconduct, burglary and armed violence, according to Paul Darrah, spokesman for the DuPage County State’s Attorney’s office.

O’Brien, an officer in the northwest suburb for 23 years, was sentenced to 24 years in prison, Darrah said. He will have to serve at least 50 percent of his sentence, a minimum of 12 years.

Also charged in the investigation were John Cichy, 30, a 10-year Schaumburg police veteran; and Matthew Hudak, 29, a five-year veteran. Both men are due back in court April 29.

All three were charged with numerous felonies, including delivery of a controlled substance, armed violence, criminal drug conspiracy, theft and burglary, prosecutors said.

The three officers allegedly took part in an elaborate plan for at least six months that involved withholding drugs taken during arrests, then reselling them through a street dealer, DuPage County prosecutors said. The drugs sold included marijuana and cocaine, authorities said.

Prosecutors also claimed they stole $20,000 from a storage locker belonging to a drug dealer, the state’s attorney’s office said in a relase.

The plan came to light in January 2013 as part of a drug investigation being conducted by Carol Stream police.

An informant told investigators the officers had contacted him about six months ago to sell drugs given to him by the cops, prosecutor Audrey Anderson said in earlier court proceedings.

After his arrest, O’Brien told investigators he took part in the scheme “for the thrill of it,” Anderson said.

“He did not have any money problems,” she said, though authorities contended the veteran officer was living “two lives.”

O’Brien was married, but also had a girlfriend living in the area with whom he had a child, Anderson said in court.

His girlfriend, 45-year-old Nicole Brehm, was also charged in the scheme for allowing the men to use her Hoffman Estates home as a “stash house” for the drugs, the release said. She pleaded guilty to one count of possession of a controlled substance on March 6 and was sentenced to 46 days in jail, and 24 months probation.

Officials from the Chicago Field Division of the Drug Enforcement Administration, along with the DuPage Metropolitan Enforcement Group and the state’s attorney’s office conducted the investigation along with Carol Stream police.