From Dawn Like Thunder (Annotated): The Barbary Wars and the Birth of the U.S. Navy, by Glenn Tucker (Corsair Books, 2019), Kindle Loc. ~630:
For nearly two hundred years the deys of Algiers had inclined toward greater independence from the Porte.
They were loosely united with the Ottoman Empire. Although the terms dey and bey are often used interchangeably, they are distinct, the dey being, after the revolt of 1710, the head officer of Algiers. The two words have different Osmanli stems, the dey coming from the Turkish dai, meaning at first a maternal uncle, but applied by the Janissaries to any well-thought-of elder.
When the Janissaries deposed the pasha and elected their own commander the head of the province, they gave him the friendly title of dey, which prevailed until the French conquest of 1830. The bey, originally beg, meant an Ottoman governor or prince, as begum meant a princess or queen. It was a more common term than dey.
Eventually beg came to be pronounced bey and moved over into the English language in that form, but its application broadened to include the ruler of a district, an appointive governor, or an individual of rank. While there were many beys among the Ottoman rulers, there was properly only one dey, the half-independent ruler of Algiers.) [sic; poorly edited] The cord with the empire was there, and at times it could be binding.