Former U.S. ambassador Marie Yovanovitch was testifying Friday in the House impeachment inquiry when suddenly President Donald Trump weighed in.

“Everywhere Marie Yovanovitch went turned bad,” the president tweeted during the public, televised hearing before the House Intelligence Committee. “She started off in Somalia, how did that go?”

Trump also asserted his “absolute right” to recall ambassadors, as he had done with Yovanovitch, whose most recent post was in Ukraine, a country at the heart of the impeachment inquiry.

Everywhere Marie Yovanovitch went turned bad. She started off in Somalia, how did that go? Then fast forward to Ukraine, where the new Ukrainian President spoke unfavorably about her in my second phone call with him. It is a U.S. President’s absolute right to appoint ambassadors. — Donald J. Trump (@realDonaldTrump) November 15, 2019

Committee Chairman Adam Schiff, D-Calif., read the tweet aloud during the hearing and asked Yovanovitch how the president's repeated attacks on her might affect other witnesses in the impeachment inquiry.

"It's very intimidating,” she said. "I can't speak as to what the president is trying to do but I think the effect is to be very intimidating."

Former U.S. Ambassador to Ukraine Marie Yovanovitch testifies before the House Intelligence Committee, on Nov. 15, 2019, on Capitol Hill. J. Scott Applewhite / AP

During a break, Schiff told reporters that "we saw today witness intimidation in real time by the president of the United States, once again going after this dedicated and respected career public servant in an effort to not only chill her, but to chill others who may come forward.

Trump told reporters later on Friday that he was just offering his opinion.

Download the NBC News app for breaking news and politics

“I have the right to speak. I have the freedom of speech just as other people do,” the president said.

But was it witness tampering, which is a violation of the law?

Why it could be prosecuted as witness tampering

Federal criminal law contains a broad prohibition against illegitimately affecting the presentation of evidence in hearings. For example, it is unlawful to knowingly use intimidation or corrupt persuasion with intent to influence the testimony of any person in an official proceeding.

An “official proceeding” includes hearings before Congress. Witness harassment also includes conduct intended to “badger, disturb or pester” and attempts to intimidate, even if the witness isn’t actually influenced, and even if the witness never actually received the threat.

An act “with the intent to influence the testimony” has the purpose of getting the person to “change, color, or shade his or her testimony in some way.” The government doesn’t have to prove that the testimony was, in fact, changed, as long as the intent was there. The government does have to prove that whatever statements were made to the person about the testimony had that improper purpose.

"Intimidation" means the use of any words designed to make someone timid or fearful. Yovanovitch all but established this prong when she testified about her reaction to the tweet: “It’s intimidating.” It seems to fit the elements of the witness-tampering statute.

How the tweet could be defended

There are two major themes for the defense, first, that the tweet did not have a bad purpose and, secondly, that the First Amendment allows the president to express his opinion.

The president's defense could point out that as the former ambassador was already recalled from her post in Ukraine and now has a good fellowship at Georgetown University, Trump's words can no longer affect her job.

The defense could also argue that his words were not a threat, but rather just an explanation that Yovanovitch was recalled because she was bad at her job.

Finally, the president's team might even argue that he has a First Amendment right to say whatever he wants about the former ambassador.

That last argument is the weakest.

Courts have rejected First Amendment challenges to witness-tampering laws. The law does not prohibit all persuasion but only that which is "corrupt," which means the government must prove the defendant was motivated by an improper purpose, with the purpose of obstructing justice. By narrowly targeting only persuasion that is "corrupt," federal law does not outlaw lawful or constitutionally protected speech and is not unconstitutionally overbroad.

Trump’s strongest argument is that his opinion about the bad job the ambassador did gives context to why she was recalled. And, since ambassadors serve at the president’s pleasure, voicing his displeasure with her service is part of his executive prerogative.

There are prosecutors who would charge this case or bring it to a grand jury on these facts. There are also prosecutors who might not bring this case.

It’s not a slam dunk, but it’s a winnable case. There are a few defenses, but the best defense is that the tweet was not motivated by any bad purpose.

Of course, a sitting president cannot be charged with a crime by the Department of Justice, but he can be impeached by Congress. That tweet could very well end up in an article of impeachment.