Years before President Donald Trump sent his all-caps tweet threatening Iranian President Hassan Rouhani, he had warned that his predecessor, Barack Obama, would use the prospect of a war with Iran for political advantage.

Late Sunday, Trump tweeted that Rouhani must "NEVER, EVER THREATEN THE UNITED STATES AGAIN" lest he "SUFFER CONSEQUENCES THE LIKES OF WHICH FEW THROUGHOUT HISTORY HAVE EVER SUFFERED BEFORE."

Trump tweet NEVER EVER

Trump's tweet, the latest instance of the rising tensions between the U.S. and Iran, appeared to be a response to Rouhani's admonition on Sunday that a war between the U.S. and Iran would be the "mother of all wars."

Despite his bellicose tweet, Trump used to express suspicions in prior tweets years ago that Obama would start a war with Iran "in order to get elected" to a second term.

Trump tweet Obama will start war

It wasn't just an off-hand remark; Trump repeated the sentiment that Obama would attack Iran as a political calculation in subsequent tweets over the next four years:

Trump tweet Obama 2012

Trump tweet Obama 2013

Trump tweet Obama 2013 2

Trump tweet Obama 2015

The president's salvo against Rouhani comes as Trump slaps punitive sanctions back on Iran after he announced the U.S. withdrawal from the 2015 nuclear deal brokered during the Obama administration.

The White House didn't immediately respond to CNBC's request for comment on Trump's previous tweets.