ORLANDO — A Florida politician considered key to the investigation of Rep. Matt Gaetz formally pleaded guilty Monday to sex trafficking of a minor and a host of other crimes, agreeing to cooperate fully with prosecutors and testify in court in hopes of leniency for himself.

Appearing in court Monday, Joel Greenberg, a former tax collector for Seminole County, Fla., repeatedly said “I do” or “yes” in response to questions from Magistrate Judge Leslie Hoffman, affirming what he had already admitted in a written plea agreement made public last week. Wearing navy blue jailhouse clothes and a mask, he appeared pale and splotchy and turned around several times to look back at the small crowd who had come to watch the hearing.

His plea and deal to cooperate is a potentially ominous sign for Gaetz (R-Fla.) because it signals prosecutors have lined up a critical witness while they continue to investigate the congressman. Gaetz has vigorously denied wrongdoing.

Rep. Matt Gaetz (R-Fla.) first got involved in politics a decade ago. It didn't take him long to find stardom in the Republican Party. (Drea Cornejo/The Washington Post)

After prosecutors and Greenberg’s defense attorney first revealed at a court hearing in April that they were working toward a deal, Fritz Scheller, Greenberg’s defense attorney, hinted the arrangement could spell trouble for Gaetz.

“I’m sure Matt Gaetz is not feeling very comfortable today,” he said then, asserting that his client was “uniquely situated” to help prosecutors and was seeking a deal “with the least exposure possible.”

Scheller suggested Monday those comments were made strategically because he hoped to develop a certain “narrative” surrounding the case.

“Last time we talked, I had a certain agenda, which I accomplished,” he said, adding, “As an attorney representing your client with the Fourth Estate, you always have an agenda, and a narrative. And now that it’s changed, there’s really nothing more for me to say.”

Scheller declined to say what Greenberg’s plea would mean for Gaetz, referring questions to Gaetz’s attorneys, and would not say how many times Greenberg met with investigators.

“To paraphrase ‘The Matrix,’ the plea agreement has a path, Mr. Greenberg just has to walk the path,” he said, referring to the popular science-fiction movie starring Keanu Reeves.

Greenberg was first charged last summer in a bare-bones indictment that accused him of fabricating allegations and evidence to smear a political opponent, but prosecutors superseded it multiple times as they uncovered more damaging evidence. He ultimately agreed to plead guilty to six criminal charges — including sex trafficking of a child, aggravated identity theft and wire fraud — which come with a mandatory minimum sentence of 12 years and a statutory maximum potentially decades longer.

In exchange, the prosecutors agreed to dismiss the other 27 counts Greenberg faced and recommend a term within federal sentencing guidelines, which are often far less than the statutory maximum penalties. They also agreed to recommend other possible sentencing breaks. If they determined, for example, that Greenberg provided “substantial assistance” in building other cases, they might ask a judge to deviate below the minimum required penalty, according to Greenberg’s plea agreement.

It was in exploring Greenberg’s conduct that investigators came upon evidence potentially implicating Gaetz in sex trafficking, people familiar with the matter have said. Prosecutors had been exploring whether Greenberg paid women to have sex with Gaetz and whether the two shared sexual partners, including the 17-year-old girl at issue in Greenberg’s case, these people said.

Gaetz, who represents a mostly conservative district in Florida’s panhandle, is known as a strident defender of former president Donald Trump. The investigation into him was opened during the Trump administration and proceeded with the approval of then-Attorney General William P. Barr.

Documents filed in association with Greenberg’s plea did not name Gaetz specifically but outlined how Greenberg paid for women and the minor to engage in sex acts not just with him, but with unidentified “others.” Greenberg has been providing investigators information about Gaetz since last year, according to a person familiar with the matter.

According to two people who heard the comments directly, Gaetz repeatedly boasted to people involved in Florida politics about women he met through Greenberg. The people, like others, spoke on the condition of anonymity because the Justice Department is still investigating the matter.

On Monday, a plane flew over the federal courthouse dragging a banner that read, “Tick Tock Matt Gaetz.”

Gaetz has specifically denied ever paying women for sex or, as an adult, having sex with a 17-year-old. His spokesman has attacked Greenberg’s credibility, noting the initial allegations surrounding Greenberg stemmed from his fabricating allegations and evidence that a schoolteacher who was running against him to be tax collector had an inappropriate sexual relationship with a student.

Greenberg also pleaded guilty to a host of other crimes, including stealing from the tax collector’s office and defrauding a government loan program that provided relief for businesses affected by the coronavirus pandemic. Though he is considered an important witness who could implicate Gaetz, he would probably face significant questions about his credibility.

Brian Beute, the schoolteacher whom Greenberg admitted to fabricating allegations against, said, “It’s a good day. It feels like a weight has been lifted.”

David Bear, his lawyer, said Republicans who supported Greenberg “have a lot to answer for.” He added that “nobody’s going to believe anything that Joel Greenberg says by itself,” but his testimony could be valuable if corroborated by other evidence or witnesses.

Zapotosky reported from Washington.