The United States and Iran traded military strikes after Washington on Friday accused Tehran of attacking a cargo ship, jeopardizing a fragile ceasefire as diplomats struggle to contain the Middle East war.