The secretary's assessment marks one of the strongest public defenses of the deal by an administration official in recent weeks. Trump has lately begun hinting that he may soon take steps to leave the landmark 2015 accord, which put limits on Iran's nuclear program in exchange for sanctions relief.
The White House is approaching an Oct. 15 deadline, when Trump must either certify to Congress that Iran is complying with the deal or give lawmakers the choice to reimpose sanctions.
Mattis weighed in during a Senate Armed Services Committee hearing on Afghanistan after being prompted by Sen. Angus King, an independent from Maine.
"Do you believe it's in our national security interest at the present time to remain in the JCPOA?" King asked, referring to the deal's official title, the Joint Comprehensive Plan of Action.
"Yes, Senator, I do," Mattis replied.
Trump has long vowed to rip up the deal, which was negotiated by the United States and five other world powers.
"The Iran Deal was one of the worst and most one-sided transactions the United States has ever entered into. Frankly, that deal is an embarrassment to the United States, and I don't think you've heard the last of it — believe me," Trump told the United Nations General Assembly last month.
However, he has twice certified to Congress that Iran is in compliance and that it remains in the national interest to continue suspending sanctions. If he refuses to certify Iran this month — which he must do every 90 days under U.S. law — Congress will get the opportunity to vote on restoring sanctions.
Restoring sanctions without showing Iran violated the deal would put the United States in violation of the accord, experts say, potentially alienating some of the nation's closest allies and touching off trade disputes.
A U.S. exit would also pave the way for Iran to resume its work on nuclear weapons by ending inspections on facilities and lifting limits on the materials Tehran is able to use.