Ex-national security adviser Michael Flynn pleaded guilty Friday to lying to the FBI about his contacts with Russia’s ambassador – saying he agreed to testify against President Trump “because it was the right thing to do for his family and the country,” according to reports.

Flynn, 53, also is prepared to testify that President Trump ordered him to reach out to Russia, contradicting the president’s claim that he had nothing to do with Russia before or after his surprise election, ABC News reported.

He pleaded guilty to “willfully and knowingly” making “false, fictitious and fraudulent statements” to the feds on Jan. 24 about talks with then-Ambassador Sergey Kislyak.

The fourth — and most senior — figure indicted so far in the probe into Russian meddling in the 2016 election, Flynn appeared in federal court in Washington shortly after the charges against him were made public.

“Yes, sir,” the retired three-star general said when asked if he wanted to plead guilty, according to Agence France-Presse.

“I accept your guilty plea,” Judge Rudolph Contreras said, adding: “There will be no trial and there will be probably no appeal.”

“My guilty plea and agreement to cooperate with the Special Counsel’s Office reflect a decision I made in the best interests of my family and of our country,” he said in a statement.

He added: “Through my faith in God, I am working to set things right. I accept full responsibility for my actions.”

Special White House counsel Ty Cobb reacted to the guilty plea by saying: “The false statements involved mirror the false statements to White House officials which resulted in his resignation in February of this year.”

“Nothing about the guilty plea or the charge implicates anyone other than Mr. Flynn. The conclusion of this phase of the Special Counsel’s work demonstrates again that the Special Counsel is moving with all deliberate speed and clears the way for a prompt and reasonable conclusion,” he said in a statement.

Flynn was charged with one count of lying about his private discussions with Kislyak about US sanctions being imposed on Moscow by the Obama administration.

“On or about January 24, 2017, defendant Michael T. Flynn did willfully and knowingly make materially false, fictitious, and fraudulent statements and representations” over a government matter, according to two-page charge sheet.

At the time, Flynn was a campaign adviser with no official US government role, but it was known he would likely become national security adviser.

He was forced to resign in February, just a month after Trump took office, because of his concerns about his contacts with Russia.

The charges alleged that Flynn falsely denied that in December 2016, when the Obama administration announced new sanctions and the expulsion of 35 Russian diplomats over Moscow’s meddling in the 2016 election, Flynn privately asked Kislyak to refrain from escalating the situation by retaliating.

Flynn also allegedly lied to investigators about Kislyak’s subsequent answer that Russia would moderate its response, according to the charging document.

Flynn, who once headed the Defense Intelligence Agency, also was accused of lying about secretly asking Kislyak in late last year to defeat or delay a vote on a pending UN Security Council resolution.

The specific resolution was not detailed, but the discussion was held a day before the Security Council voted to condemn Israel’s settlements in Palestinian territory.

In a rare step that stunned its Middle East ally, the Obama administration had abstained on the motion rather than veto it as had been done in the past.

Days earlier, Trump had sought to block the motion, personally asking Egypt’s President Abdel Fattah al-Sisi to put it on ice.

The single charge is not expected to end Flynn’s legal woes with Mueller’s team, which also is probing his other contacts with Russia and his work as an unregistered lobbyist for Turkey before and after the Nov. 8 election.

Flynn is the first Trump administration official and the fourth tied to the campaign to be charged as part of Mueller’s widening probe into possible collusion between the Kremlin and Team Trump, as well as potential obstruction of justice and financial crimes.

Former Trump campaign chairman Paul Manafort and his deputy, Rick Gates, were arrested on money laundering and tax-related charges in relation to their work for Moscow-backed Ukrainian leader Viktor Yanukovych.

They were indicted last month and pleaded not guilty.

And Trump campaign foreign policy adviser George Papadopoulos pleaded guilty to making a false statement to the feds after seeking to arrange a pre-election meeting between Trump and Russian President Vladimir Putin.

Papadopoulos pleaded guilty to a charge of lying to investigators in a deal that made clear he was cooperating in their investigation.