Mr. Kerry has also been trying to save it. He has strategized with Foreign Minister Mohammad Javad Zarif of Iran, met with European officials and lobbied members of Congress.

Mr. Trump did not specify what was illegal about Mr. Kerry’s actions, and the White House would not comment. But Rudolph W. Giuliani, the president’s personal lawyer, accused Mr. Kerry of “violating the Logan Act,” adding, “And nobody seems to care.”

As The New York Times’s Charlie Savage has previously explained:

The Logan Act is a 1799 statute that bars private citizens from interfering with diplomatic relations between the United States and foreign governments. It makes it a felony, punishable by a fine or imprisonment of up to three years, if an American citizen, without government authorization, interacts “with any foreign government or any officer or agent thereof, with intent to influence the measures or conduct of any foreign government or of any officer or agent thereof, in relation to any disputes or controversies with the United States, or to defeat the measures of the United States.”

A spokesman for Mr. Kerry declined to comment on Monday on Mr. Trump’s charges of illegality. A statement released by Mr. Kerry’s office said he “stays in touch with his former counterparts around the world just like every previous secretary of state.”

“Like America’s closest allies,” the statement said, “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.”