Then-Secretary of State John F. Kerry in 2016. (Andrew Harnik)

President Trump on Monday castigated John F. Kerry following a report that the former secretary of state was engaged in unusual shadow diplomacy in a bid to preserve the pact he helped negotiate to limit Iran’s nuclear program.

“The United States does not need John Kerry’s possibly illegal Shadow Diplomacy on the very badly negotiated Iran Deal,” Trump wrote on Twitter. “He was the one that created this MESS in the first place!”

In recent months, Kerry has been quietly holding meetings and speaking by phone with players in the Iran nuclear agreement, one of the former Massachusetts senator’s major diplomatic achievements, the Boston Globe reported Friday.

The paper said Kerry has been seeking to apply pressure on the Trump administration from the outside to preserve the pact. Trump, who campaigned in 2016 on scrapping it, faces a Saturday deadline to decide whether to continue abiding by its terms.

During a Friday speech to the National Rifle Association, Trump attacked Kerry for having negotiated the 2015 deal he called “horrible.”

“We have the former administration as represented by John Kerry, not the best negotiator we’ve ever seen,” Trump said. “He never walked away from the table, except to be in that bicycle race where he fell and broke his leg.” (Kerry broke his leg in 2015 while bicycling in the Alps.)

Since the Globe report, Kerry has come under fire from conservative commentators, with some suggesting his dealings with foreign officials could violate the Logan Act. That law prohibits private citizens from negotiating on behalf of the U.S. government without authorization.

There are only two known instances in which individuals have been indicted for violating the Logan Act — most recently in 1853 — and neither indictment resulted in conviction, according to legal experts.

The Logan Act received renewed scrutiny following the Trump transition. Last year, Trump’s former national security adviser Michael Flynn pleaded guilty to lying to the FBI about conversations about sanctions with the then-Russian ambassador while President Barack Obama was still in office.

Following Trump’s tweet on Monday, Kerry spokesman Matthew Summers released a statement defending his actions.

“I think every American would want every voice possible urging Iran to remain in compliance with the nuclear agreement that prevented a war,” the statement said. “Secretary Kerry stays in touch with his former counterparts around the world just like every previous Secretary of State. Like America’s closest allies, he believes it is important that the nuclear agreement, which took the world years to negotiate, remain effective as countries focus on stability in the region.”