A former UN weapons inspector has been convicted of having unlawful contact with a minor, after being nabbed in an online sex sting.

Scott Ritter, 49, exchanged explicit messages with a detective posing as a 15-year-old girl and masturbated even after the undercover officer stressed during the chat that he was a minor, prosecutors said.

Scott Ritter walks out of the court room after the hearing.

A jury in the US state of Pennsylvania found Ritter guilty on six counts on Thursday, with sentencing set for next month.

Ritter took the witness stand in his own defence on Wednesday and said he believed the person he met in a Yahoo chat room on February 7, 2009, was an adult acting out her own fantasy.