WICHITA, Kan. -- Law enforcement officers in Kansas are now banned from having sex with people they stop for traffic violations or detain in criminal investigations under a new state law that many legislators were surprised was necessary.

Before Gov. Jeff Colyer signed the law Thursday, Kansas was among 33 states where consensual sex between police and people in their custody wasn't a crime, The Wichita Eagle reported .

Law enforcement officers were banned from having sex with people in jail, but the new law bans sexual relations "during the course of a traffic stop, a custodial interrogation, an interview in connection with an investigation, or while the law enforcement officer has such person detained."

Democratic Rep. Cindy Holscher, of Olathe, introduced the bill. She said the legislation grew from the case of Lamonte McIntyre, who spent 23 years in prison for a double murder he didn't commit.

McIntyre was released last year after investigators determined the detective who arrested him had long coerced sexual acts from women in Kansas City's black community, including McIntyre's mother, by threatening to arrest them or their relatives. McIntyre's mother said in an affidavit that she believed the detective targeted her son after she spurned his advances.

Holscher said she also was influenced by a New York case where a teenager alleged she was raped by two police officers in the back of their van. No charges were filed because the officers claimed the sex was consensual and therefore legal.

The Kansas bill received bipartisan support. Rep. John Carmichael, a Democrat from Wichita, said he was shocked to learn that such behaviour wasn't already illegal in Kansas when Holscher first discussed the proposal.

Many officers now wear body cameras, so it would be difficult for law enforcement to get away with sex on the job, said Rep. John Whitmer, a Republican from Wichita.

"Most officers are great guys and women who are working hard, but there's always the one," Whitmer said.