Iran has warned that it would retaliate after American military forces attacked sites near the Strait of Hormuz.