The Battle of Baekgang was the naval battle of 663 at the mouth of the Baekgang (the mouth of the Geum river in Korea) between the allied Tang and Silla fleets and the Japanese force that had come to the aid of the Baekje restoration. After the Tang-Silla armies destroyed Baekje in 660, Baekje's surviving loyalists rose to restore the kingdom and appealed to the Yamato court, which — to keep its footing on the peninsula — sent tens of thousands across in successive waves to join the Baekje remnants. In 663 some 400 Japanese warships met the 170-odd ships of the Tang general Liu Rengui at the Baekgang mouth: in close order and with fire attack the Tang won four engagements running, most of the Japanese hulls burned, the invasion broken — and the restoration movement failed with it. Japan then quit the peninsula entirely, built coastal defenses against a possible Tang descent, and at the same time made peace with the Tang: the missions to Tang grew in size, the codes and institutions of the Tang were taken over wholesale, and the shaping of Japan's state after the Taika Reform owes this defeat its deepest lesson.