A former Minnesota FBI agent who shared classified information with the media was sentenced to four years in prison Thursday.

Terry J. Albury, who had served in the agency since 2001, admitted earlier this year that he shared secret FBI documents on recruiting informants and threats from an unspecified Middle Eastern country with a reporter.

He provided at least 25 documents, 16 of which were classified, according to court documents.

“I apologize to everyone I have hurt as a result of my actions, especially, my family, my co-workers in California and Minneapolis, and my colleagues in the law enforcement community,” Albury wrote in a letter to the court.

Albury’s sentencing in federal court in St. Paul, Minn., comes a day after prosecutors charged a senior Treasury Department employee with leaking sensitive financial information to a reporter. The cases are part of a crackdown by the Trump administration on leaks to the media.

Albury’s is the second-longest sentence imposed by a federal court in a media leak case, according to the Justice Department. In August, former NSA contractor Reality Winner was sentenced to five years and three months for leaking a top-secret agency document on Russian hacking.

Although the reporter in Albury’s case is not named, the dates in his plea agreement match a series of articles published by The Intercept that detail how the FBI surveils both informants and suspected terrorists.

In a written declaration, the assistant director of the FBI Counterintelligence Division, E.K. Priestap, wrote that Albury’s leak “may erode the FBI’s ability to collaborate with various public and private entities in conducting counterterrorism and intelligence operations.”

Albury’s attorneys said in a sentencing memorandum that he was a whistleblower compelled to expose what he saw as a counterproductive approach to counterterrorism rooted in racial and religious bias.

His crime was “an act of conscience, of patriotism and in the public interest, and for no personal gain whatsoever,” JaneAnne Murray and Joshua L. Dratel wrote.

Albury, the son of an Ethio­pian refu­gee, was the only black field agent in Minnesota for the five years he worked there. He said he routinely heard other agents make “racial jokes and slurs” as they investigated support for the terrorist group al-Shabab in the area’s Somali Muslim population.

He was also “increasingly troubled” by the way the FBI investigated counterterrorism, using informants he saw as unreliable and surveillance he deemed excessive, his attorneys wrote.

He felt that cases were often weak and served only to deepen mistrust of law enforcement among people who could give useful information.

During a deployment to Iraq, Albury’s attorneys said he “frequently witnessed deep animus held by U.S. personnel toward Iraqis, and, on more than one occasion, believed that he was complicit in acts of torture.”

Prosecutors say that if Albury was so disturbed, he could have quit the FBI, and if he had witnessed illegal behavior he should have gone to the Justice Department’s inspector general or special counsel.

Albury “was miserable and hated working at the FBI but never sought to leave . . . disagreed with FBI policies, but said and did nothing to try to change those policies and accepted awards for conduct in accordance with those policies,” prosecutors Patrick Murphy and Danya Atiyeh wrote in one filing.

Instead, they said he spent 18 months committing acts he knew to be criminal.

Albury would get to work early to photograph documents without being seen, then turn them into new file formats to avoid detection before sending them to the reporter through an encrypted email program and wiping his laptop’s data. Prosecutors say they found 70 documents, 50 of which were classified, on a storage device in a shirt pocket in his home.

Albury’s attorneys say he did voice his concerns with supervisors but got no response, leading him to believe any other complaint would “fall simply fall on deaf ears.”

Attorney General Jeff Sessions said last year that the Justice Department had more than tripled the number of leak probes compared with the number ongoing when Trump took office. Trump had criticized Sessions as being “weak” on rooting out leakers and has decried what he sees as politically motivated leaks by officials seeking to undermine him.

In the past 16 months, the Trump administration has charged five people — two were contractors and one worked for the U.S. Senate — in leak-related cases, though some were charged with lying rather than with disclosure. The rate nearly matches that of the Obama administration, which brought five such cases between December 2009 and December 2010 alone.

“The pace is not slowing down; it’s accelerating,” said Steven Aftergood, a national security expert with the Federation of American Scientists.

That is worrisome to advocates for press freedom, but applauded by officials who view unauthorized disclosures as harmful to national security.

“There’s an enduring tension between government secrecy and a free press, and there’s a public interest in both,” said Aftergood, who directs the Project on Government Secrecy. “You want the government to be able to keep legitimate secrets, and you want the press to be able to uncover things that are unnecessarily being withheld. It looks like in recent years the balance has been tipping in favor of law enforcement.”

In a statement, the Intercept did not say whether Albury was a source but described him as a “whistleblower motivated by his concern about the bureau’s pattern of racial profiling and discrimination.”

Prosecutors have charged Albury and a number of other defendants under the Espionage Act, a 1917 law passed to punish spying and to prevent support for the United States’ enemies during World War I. It has been amended many times, and in the last decade or so has been used to punish leakers of classified secrets. The law bars the unauthorized disclosure and the retention of information “related to the national defense” — the charge lodged against Albury.