The United States Navy’s first real offensive success was at the Battle of Midway. Allied forces had broken the Imperial Navy’s codes and were able to intercept the Japanese attack and turn it around in their favor. Japan lost a large number of men and artillery, and thus the tide turned in the Pacific. Years later, American forces would once again prevail in the Battle of Leyte Gulf, despite large losses in manpower and carriers. Although the Japanese battleship Yamato and the remaining force returned to Japan, the battles marked the final defeat of the Japanese Navy, as the ships remained in port for most of the rest of the war and ceased to be an effective naval force.