Donald Trump. Kevin Lamarque/Reuters

President Donald Trump went off script during his Wednesday commencement speech to Coast Guard Academy graduates, saying critics and the media had treated him more unfairly than any politician "in history."

His comments were the first he has made publicly since The New York Times published a bombshell story on Tuesday that said James Comey, the FBI director whom Trump fired last week, kept memos of his meetings with Trump and had documented one in which the president said he hoped Comey would let go of the FBI's investigation into Michael Flynn, the former national security adviser.

Legal experts have said that could lead to a "very strong case of obstruction of justice," the same charge that brought down President Richard Nixon.

"Now, I want to take this opportunity to give you some advice," Trump told the Coast Guard cadets in Connecticut. "Over the course of your life, you will find that things are not always fair. You will find that things happen to you that you do not deserve and that are not always warranted, but you have to put your head down and fight, fight, fight. Never, ever, ever give up. Things will work out just fine.

"Look at the way I've been treated lately," he continued. "Especially by the media. No politician in history — and I say this with great surety — has been treated worse or more unfairly. You can't let them get you down. You can't let the critics and the naysayers get in the way of your dreams. I guess that's why, thank you, I guess that's why we won."

Trump told the cadets that "adversity makes you stronger" and to never "give in," "back down," or "stop doing what you know is right."

"Nothing worth doing ever, ever, ever came easy," he said. "And the more righteous your fight, the more opposition that you will face."

He then listed some of what he believes are his early accomplishments in office, such as the confirmation of Justice Neil Gorsuch to the Supreme Court and what he said was a significant drop in the number of illegal border crossings from Mexico into the US.

Trump has faced a barrage of negative news since his controversial firing of Comey. In addition to the Times report, The Washington Post reported on Monday that Trump disclosed highly classified intelligence about ISIS from an ally — later revealed to be to Israel — to Russian diplomats during a recent Oval Office meeting.

Watch Trump's comments: