The Iranian military has halted the routine harassment by its armed “fast boats” of U.S. naval vessels in the Persian Gulf, the U.S. military said, a turnabout that officials welcomed but were at a loss to explain.

The boats for at least two years would dart toward the U.S. vessels as they passed through the Persian Gulf, risking miscalculation, but haven’t done so for five months, U.S. military officials said.

The...