Kraków was almost entirely destroyed during the Mongol invasion of Poland in 1241, after the Polish attempt to repulse the invaders had been crushed in the Battle of Chmielnik. Kraków was rebuilt in 1257, in a form which was practically unaltered, and received self-government city rights from the king based on the Magdeburg Law. In 1259, the city was again ravaged by the Mongols, 18 years after the first raid. A third attack, though unsuccessful, followed in 1287. The year 1311 saw the Rebellion of wójt Albert against Polish High Duke Władysław I. It involved mostly German-speaking citizens of Kraków who, as a result, abandoned their political ambitions. However, the rebellion cost Poland the city of Gdańsk (Danzig), which was taken over by the Teutonic Order in 1309.