An IRS staffer who leaked confidential details about former Trump lawyer Michael Cohen's finances to Michael Avenatti, ex-lawyer for adult film star Stormy Daniels, pleaded guilty Wednesday to illegally accessing and distributing that information.

John C. Fry was an investigative analyst with the IRS Criminal Investigation Division, the law enforcement arm of the agency, in May 2018 when he twice logged on to the Financial Crimes Enforcement Network (FinCEN) database and downloaded five Suspicious Activity Reports (SARs) — reports filed by banks when they note potentially suspicious transactions — related to Cohen and his company Essential Consultants.

In court Wednesday, Fry admitted giving Avenatti the information via cellphone and emailing him screenshots of the SARs. He pleaded guilty to one county of unauthorized disclosure of SARs.

Avenatti made the information public via Twitter, noting Cohen's receipt in 2017 of $500,000 from Columbus Nova, a company with ties to a Russian billionaire, and payments to Essential Consultants from other firms that do business with the federal government, including AT&T.

At the time, Avenatti was representing Daniels in legal actions against President Donald Trump over a nondisclosure agreement she signed just prior to the 2016 election. Cohen has admitted arranging the $130,000 hush-money payment to Daniels and pleaded guilty to a campaign finance violation, saying he paid her "at the direction of the candidate" and did so to influence the election.

"Fry was given access to sensitive and powerful government databases including people’s most private financial information and he was given that access to do his job as an investigative analyst," David L. Anderson, the U.S. attorney for the Northern District of California, said. "He decided his politics were more important than his obligation to follow the law. In that, he was mistaken."

Avenatti faces federal charges of extortion and fraud in separate cases, but has not been charged with any wrongdoing in the Fry case. In a February statement, Avenatti told NBC News he did nothing wrong and did not violate any law by receiving the information, likening his situation to reporters who don't violate the law "when they do their jobs."

After Avenatti disclosed the information, the Treasury Department's Office of Inspector General announced it would be looking for the source.

Fry was confronted by federal investigators in February 2019 and admitted providing the SARs to Avenatti, according to prosecutors.

Fry faces a maximum sentence of five years in federal prison and up to a $250,000 fine.