WASHINGTON — In a vivid illustration of the tensions between the United States and Iran, an American Navy warship fired warning shots at Iranian boats that were racing toward it near the Strait of Hormuz, Defense Department officials said on Monday.

The episode occurred Sunday when four Iranian fast boats came within 900 yards of the U.S.S. Mahan, a guided missile destroyer that was escorting an amphibious warship with 1,000 Marines on board and a Navy oiler.

When the Iranian boats did not respond to a radio call and flares signaling them to stop, the American destroyer fired three warning shots with a .50-caliber machine gun. A Navy helicopter also dropped smoke grenades. There was no damage to the Iranian vessels, and they did not return fire.

It was the first time the Navy had fired warning shots at an Iranian boat since Aug. 24.

Though the boats’ approaches are essentially a form of harassment, they point to the risk of military confrontation in a region that is bristling with Western, Arab and Iranian forces. President-elect Donald J. Trump vowed during the presidential campaign to take military action against Iranian ships that approached American vessels in a threatening manner.