Washington (CNN) Former President Barack Obama on Tuesday criticized President Donald Trump's decision to exit the Iran deal, a pillar of Obama's legacy on foreign policy.

"Indeed, at a time when we are all rooting for diplomacy with North Korea to succeed, walking away from the JCPOA risks losing a deal that accomplishes -- with Iran -- the very outcome that we are pursuing with the North Koreans," Obama said in a statement. "That is why today's announcement is so misguided."

Trump announced on Tuesday afternoon that he was withdrawing the US from the nuclear agreement with Iran and said he would impose new sanctions.

In his statement defending the multiparty agreement with Iran, known as the Joint Comprehensive Plan of Action, Obama cited many who support the deal, including the US' European allies, and he invoked the support of US Secretary of Defense James Mattis, who has said it is in the interest of the US to stay in the agreement.

"In a democracy, there will always be changes in policies and priorities from one Administration to the next," Obama's statement continued. "But the consistent flouting of agreements that our country is a party to risks eroding America's credibility, and puts us at odds with the world's major powers."

Read More