WASHINGTON—The Trump administration exchanged threats with Iran, turning to a longstanding security concern and a top foreign-policy focus of President Donald Trump’s key supporters.

In a Twitter message addressed “To Iranian President Rouhani,” Mr. Trump wrote: “NEVER, EVER THREATEN THE UNITED STATES AGAIN OR YOU WILL SUFFER CONSEQUENCES THE LIKES OF WHICH FEW THROUGHOUT HISTORY HAVE EVER SUFFERED BEFORE.”

The...