In the early 18th century, the Ottoman Empire was losing its grip on its North African holdings, including Tripoli. A period of civil war ensued, with no ruler able to hold office for more than a year. Ahmed Karamanli, a Janissary and popular cavalry officer, murdered the Ottoman governor and seized the throne in 1711. After persuading the Ottomans to recognize him as governor, Ahmed established himself as pasha and made his post hereditary. Though Tripoli continued to pay nominal tribute to the Ottoman padishah, it acted otherwise as an independent kingdom.
An intelligent and able man, Ahmed greatly expanded his city's economy, particularly through the employment of corsairs on crucial Mediterranean shipping routes; nations that wished to protect their ships from the corsairs were forced to pay tribute to the pasha. On land, Ahmed expanded Tripoli's control as far as Fezzan and Cyrenaica before his 1745 death.
Ahmed's successors proved less capable rulers, however, and the kingdom was soon wracked by internal strife. The Karamanli dynasty would end a century later as the Ottomans retook control.