Nepal was united into a kingdom in the latter half of the eighteenth century by King Prithvi Narayan Shah of Gorkha out of a large conglomeration of petty kingdoms. At first the kingdoms retained varying degrees of local autonomy within the unified State, depending on how vigorously they had resisted Prithvi. After they consolidated power, however, the Shah dynasty began reducing the prerogatives of the local rajas and centralizing the administration.