The Kingdom of Norway as a unified realm dates to the reign of King Harald I Fairhair in the 9th century. His efforts in unifying the petty kingdoms of Norway resulted in the first known Norwegian central government. The country, however, soon fragmented and was collected into one entity in the first half of the 11th century, and Norway has retained a monarchy since that time. Traditionally, it has been viewed as being ruled by the Fairhair dynasty, though modern scholars question whether the eleventh century kings and their successors were truly descendants of Harald. Fairhair dynasty, traditional and modern views According to the traditional view, Norway was the hereditary kingdom of the 'Fairhair' dynasty, agnatic (patrilineal) descendants of the first unifier-king, Harald Fairhair. The successors to the throne after year 872 were all placed by among Harald's male descendants in historical accounts from centuries later. In the 13th century, the kingdom was officially declared hereditary by law, in contrast with the other Scandinavian monarchies which were elective kingdoms in the Middle Ages. Harald Fairhair was the first king of all Norway, bringing the lands of what had previously been several distinct petty-kingdoms under his control. The foundation of this unified Norwegian kingdom is traditionally dated to 872, when he defeated the last petty kings who resisted him at the Battle of Hafrsfjord, though the consolidation of his power took many years. Fairhair's kingdom spanned the coastal areas north to Trøndelag, but upon his death the kingship was fragmented back into the petty kingdoms, most being held by Harald's sons, descendants or allies, though there were also districts in the hands of other dynasties, such as Ladejarls. Nonetheless, the concept of control by a central power had come into existence. It remains disputed the degree to which Norway should be viewed as an hereditary kingdom under Fairhair's sons and successors, Eric I of Norway and Haakon I of Norway. Some historians emphasize their inability to exercise actual monarchical control over the country and assert that St. Olav (Olaf II), who reigned from 1015, was the first king since Fairhair to control the entire country. Olav is traditionally held to be the driving force behind Norway's final conversion to Christianity. He was later also revered as Rex Perpetuum Norvegiæ (Latin: eternal king of Norway). Only under half-brothers Olav II and Harald III would succession begin to be determined by rules of