Iran faces increased U.S. pressure and looming sanctions after Trump's decision to withdraw the United States from a 2015 international deal over Iran's nuclear program.
Addressing a gathering of Iranian diplomats, Rouhani said: "Mr Trump, don't play with the lion's tail, this would only lead to regret," the state new agency IRNA reported.
"America should know that peace with Iran is the mother of all peace, and war with Iran is the mother of all wars," Rouhani said, leaving open the possibility of peace between the two countries, at odds since the 1979 Islamic Revolution.
"You are not in a position to incite the Iranian nation against Iran's security and interests," Rouhani said, in an apparent reference to reported efforts by Washington to destabilize Iran's Islamic government.
In Washington, U.S. officials familiar with the matter told Reuters that the Trump administration had launched an offensive of speeches and online communications meant to foment unrest and help pressure Iran to end its nuclear program and its support of militant groups.
Current and former U.S. officials said the campaign painted Iranian leaders in a harsh light, at times using information that is exaggerated or contradicts other official pronouncements, including comments by previous administrations.
Rouhani scoffed at Trump's threat to halt Iranian oil exports and said Iran has a dominant position in the Gulf and the Strait of Hormuz, a major oil shipping waterway.
"Anyone who understands the rudiments of politics doesn't say 'we will stop Iran's oil exports'...we have been the guarantor of the regional waterway's security throughout history," Rouhani said, cited by the semi-official ISNA news agency.
Iran's Supreme Leader Ayatollah Ali Khamenei on Saturday backed Rouhani's suggestion that Iran may block Gulf oil exports if its own exports are halted.
Rouhani's apparent threat earlier this month to disrupt oil shipments from neighboring countries came in reaction to efforts by Washington to force all countries to stop buying Iranian oil.
Iranian officials have in the past threatened to block the Strait of Hormuz in retaliation for any hostile U.S. action.
On Sunday, Iran's ground forces commander became the latest military figure to back Rouhani's apparent threat, the semi-official news agency Tasnim reported.
"The Strait of Hormuz region must either be safe for all or be insecure for everyone," said General Kioumars Heydari, quoted by Tasnim.
Separately, a top Iranian military commander warned that the Trump government might be preparing to invade Iran.
"The enemy's behavior is unpredictable," Tasnim quoted military chief of staff General Mohammad Baqeri as saying.
"Although the current American government does not seem to speak of a military threat, according to precise information it has been trying to persuade the U.S. military to launch a military invasion (of Iran)," Baqeri said.
Iran's oil exports could fall by as much as two-thirds by the end of the year because of new U.S. sanctions, putting oil markets under huge strain amid supply outages elsewhere.
Washington initially planned to shut Iran out of global oil markets completely after Trump abandoned the deal that limited Iran's nuclear ambitions, demanding all other countries stop buying Iranian crude by November.
But the United States has somewhat eased its stance, saying it may grant sanction waivers to some allies that are particularly reliant on Iranian supplies.
(Reporting by Dubai newsroom; editing by Jason Neely and Dale Hudson)