Gwanghaegun was the second son of King Seonjo, born to Lady Kim (Gongbin), a concubine. When Japan invaded Korea to attack the Ming Empire, he was installed as Crown Prince. When the king fled north to the border of Ming, he set up a branch court and fought defensive battles. During and after the Seven Year War (1592–1598), he acted as the de facto ruler of the Joseon Dynasty, commanding battles and taking care of the reconstruction of the nation after the devastating wars, in the place of old and weak King Seonjo.