ISLAMABAD — The United States and Iran have reached an agreement to end the war and open the Strait of Hormuz , offering relief to the global economy more than three months since fighting began.