The Justice Department's internal watchdog referred former FBI Director James Comey for prosecution over the leaking of some of his memos to the media, law enforcement sources told NBC News Thursday.

The Department of Justice, however, declined to prosecute Comey, the sources said.

The memos, which Comey asked a friend to leak to The New York Times after President Donald Trump fired him, detailed conversations Comey had with the president related to the FBI’s probe of the president and Russian election interference.

The Justice Department inspector general had been probing the classification status of information in Comey's memos.

News of the inspector general’s referral of the Comey matter — and the decision by the Justice Department to not prosecute him — was first reported by The Hill.

Comey, in June 2017 testimony to the Senate Intelligence Committee, said his decision to have his memos shared publicly came after Trump had tweeted in May of that year that Comey had "better hope that there are no 'tapes' of our conversations before he starts leaking to the press!" Comey had shared the documents with Daniel Richman, an attorney and a professor at Columbia University Law School, who later shared them with a reporter from The New York Times.

Trump fired Comey on May 9, a week before the memos were leaked. The leaked memo said that Trump had asked him to shut down an investigation into former National Security Adviser Michael Flynn, raising questions about potential obstruction of justice by the president.

Comey testified that he asked "a good friend of mine who's a professor at Columbia Law School" to provide the contents of a memo to an unnamed reporter. He didn't name the professor to the committee, but multiple outlets, including NBC News, quickly identified him as Richman.

“I was worried it would be like feeding seagulls at the beach if it was I who gave it to the media, so I asked my friend to," he said.

The memo was part of a paper trail Comey built documenting what he believed to be Trump's campaign to derail the FBI's investigation of alleged Russian ties to his presidential campaign, NBC News reported in May 2017.

Ultimately, Comey said during his June 2017 testimony, he wanted his memo released because "I thought it might prompt the appointment of a special counsel" to lead the Russia investigation.

The day after The New York Times in May 2017 published a report about the memos, the Department of Justice announced that former FBI Director Bob Mueller would take over the investigation as special counsel.

The turn of events left Trump furious, leading him on a years-long, Twitter-fueled warpath against Comey and the credibility of the special counsel.

In the end, Mueller's report, released earlier this year, did not prove that Trump committed any crimes. But the report also "did not exonerate him" from obstruction of justice allegations. It pointed to several specific instances of possible obstruction by Trump — including his pressuring of Comey to end the probe of Flynn.

Trump, asked by reporters at the White House later Thursday for his response to the news, said he had not been aware of the development but nonetheless maintained that “what James Comey did was illegal.”