President Donald Trump, left, stands with Attorney General Jeff Sessions on December 15, 2017 in Quantico, Virginia, before participating in the FBI National Academy graduation ceremony.

Shortly after blasting the FBI's handling of the Hillary Clinton probe as "really, really disgraceful," President Donald Trump told an audience at the FBI Academy on Friday that he is more loyal to them "than anyone else could be."

"Anti-police sentiment is wrong and it's dangerous," he told the 200 or so law enforcement officers from different agencies around the country who came to the FBI for a six-week leadership training course.

Trump's remarks at the Quantico, Virginia, center came just about 90 minutes after he told reporters, "it's a shame what's happened with the FBI."

Speaking on the White House South Lawn before departing for Quantico, Trump claimed that the public is "very very angry" at the FBI's handling of the 2016 Clinton email investigation, which found no grounds for a criminal prosecution of the Democratic presidential candidate.

Trump said he was going to the FBI's campus, "on behalf of the FBI ... But when everybody — not me — when everybody — the level of anger at what they've been witnessing with respect to the FBI is certainly very sad."

By the time the president stepped on stage in Quantico, however, his tenor had changed markedly.

"The president of the United States has your back 100 percent," Trump told the graduates. "I will fight for you and I will never, ever let you down. Ever."

As evidence of his loyalty, Trump touted his decision to allow local law enforcement to access surplus military equipment, and said "anyone who kills a police officer should get the death penalty."

Trump also spoke at length about the "great threats" facing America, including terrorism. Speaking of two recent terror attacks in New York, Trump said the suspects in the two separate attacks were linked by one thing: They both came to the United States "through our dysfunctional immigration system."

Trump then attacked the U.S. green card lottery system using heated rhetoric that was reminiscent of his 2016 campaign rallies. "They give us their worst people. They put them in a bin. But in his hand when he's picking them, is really the worst of the worst. 'Congratulations, you're going to the United States,'" Trump said.

This is not how the Diversity Visa Lottery program works, however. In reality, applicants must meet strict eligibility requirements, which include having no criminal record, before even being admitted to the lottery. Names are then selected electronically, at random, by the State Department.

CNBC reached out to the White House to ask whether the president fully understands how the green card lottery works. And if he does, why Trump would characterize it as a program that operated outside of the United States when it is in fact run by the Trump administration's State Department. A spokeswoman did not immediately respond.

Near the end of his remarks, Trump took a familiar jab at the traveling pool of journalists covering the event. "There's the fake news back there," Trump said, pointing to the press box. "Fake news. No, in fact, some of them are fine people. About 30 percent."

Later in the day, the president was expected to travel to Camp David, Maryland, where he will spend the weekend.