Joel Greenberg, Rep. Matt Gaetz’s former confidante, pleaded guilty in federal court in Orlando Monday.

“Do you plead guilty because you are guilty?” said Judge Leslie Hoffman of the United States Magistrate Court.

“Yes,” said Mr. Greenberg, who was wearing dark blue overalls and a white surgical mask and was handcuffed.

Mr Greenberg admitted a number of crimes in a plea agreement filed on Friday. At Monday’s hearing, that agreement was formalized and Mr Greenberg answered questions from a judge before admitting his guilt.

Mr. Gaetz is under investigation to see if he violated sex trafficking laws by paying the same 17-year-old for sex. On Monday, Mr. Gaetz’s name was neither mentioned in court nor mentioned in court documents filed on Friday.

Mr Greenberg faces over 12 years in prison but it was unclear when he will be sentenced. As part of his informed consent, he will have to give significant help to the Justice Department’s prosecution of others in order to convince a judge to give him a lighter sentence. Defense lawyers typically want to postpone the conviction for as long as possible in order to give their clients the maximum possible time to help the government.

Mr. Greenberg, a Republican, was a freshman in politics when he won a 2016 local election to become a tax collector in Seminole County, Florida, north of Orlando.

Shortly after taking office, he began a series of fraud and other crimes, according to court documents, including using taxpayers’ money to pay women for sex and buying sports memorabilia.

He was tried for the first time last June. Mr. Greenberg began working with the government late last year when he discovered that prosecutors had substantial evidence against him and that if tried and lost, he could spend decades in prison.

Mr. Greenberg’s lawyer, Fritz Scheller, had told reporters after a court hearing last month: “I’m sure Matt Gaetz is not feeling very well today.” But he declined to elaborate on it.

When asked in front of the courtroom on Monday whether Mr. Greenberg will work together against Mr. Gaetz, Mr. Scheller gave a more moderate answer.

“He is bound by the objection agreement – he will keep it,” said Mr. Scheller.