Rouhani vowed to continue his efforts to end the country's isolation as he was sworn in by supreme leader Ayatollah Ali Khamenei following his re-election in May.
But the ceremony came less than 24 hours after US President Donald Trump confirmed fresh sanctions against Iran.
Tehran says the new measures violate its 2015 deal with world powers that eased sanctions in exchange for curbs on its nuclear programme, an agreement which Trump has repeatedly threatened to tear up.
"We will certainly not fall into the trap of US policy and Trump, and our reaction will be very carefully considered."
Also Read
The mounting crisis creates a difficult position for Rouhani, a 68-year-old moderate who won re-election largely thanks to his efforts at repairing relations with the West.
"We will never accept isolation," Rouhani said as he was sworn in in front of top political and military officials.
"The nuclear deal is a sign of Iran's goodwill on the international stage," he added.
"The enemy's hostility has made us more resistant," he said.
New US sanctions have emboldened Rouhani's hardline opponents, who say he should never have trusted the United States.
"It's unfortunate timing," said Ellie Geranmayeh, an Iran analyst with the European Council on Foreign Relations.
"What will be absolutely critical is how the Europeans position themselves," she said, pointing to the burgeoning trade ties with Europe and their continued backing of the nuclear deal.
Britain, France and Germany -- who signed the deal along with Russia, China and the United States -- remain firm backers of the agreement and have criticised the Trump administration for threatening to scrap it.
"What Iranians are banking on at the moment, maybe overestimating, is that Europe will safeguard and build on the deal, and make it too politically costly for Trump to tear it up, or at least show Washington that if it walks away, it will be doing so alone," said Geranmayeh.
The International Atomic Energy Agency has repeatedly certified that Iran is sticking by its commitments under the agreement -- a position that has been reluctantly accepted by the Trump White House.
But with Iran gaining the upper hand across the Middle East, through its support for proxies in Syria, Lebanon and Iraq, US lawmakers appear determined to ratchet up tensions.
Since the election, he has engaged in a war of words with the Revolutionary Guards over their outsized role in the economy -- although they have since sought to bury the hatchet with a public show of unity.
Disclaimer: No Business Standard Journalist was involved in creation of this content