During the Heian period, the island was attacked by Jurchen pirates in the Toi invasion of 1019. Afterwards, the islands came under the rule of the Matsura clan, who developed trade and commercial relations between Goryeo in Korea, Tsushima, Iki and Kyushu. However, the islands were again devastated by the Kamakura period Mongol invasions of Japan in 1274 and 1281 during which time many of its inhabitants were slaughtered. Throughout the Muromachi period, the islands were a main base for the Japanese Wokou pirates, who plundered coastal settlements in Korea and China. Following the establishment of the Tokugawa shogunate in the Edo period, the islands came under the rule of Hirado Domain.