The Ottoman Uluç Ali Reis, at the head of an army of janissaries and Kabyles, retook Tunis in 1569. However, following the Battle of Lepanto in 1571, the Spanish under John of Austria succeeded in retaking the city and re-establishing the Hafsid sovereign in October 1573. Following these conflicts, the city finally fell into Ottoman hands in August 1574. Having become an Ottoman province governed by a Pasha who was appointed by the Sultan based in Constantinople, the country attained a degree of autonomy. After 1591, the Ottoman governors (Beys) were relatively independent, and both piracy and trade continued to flourish. Under the rule of deys and Moorish beys, the capital sprang into new life. Its population grew by additions from various ethnicities, among which were Moorish refugees from Spain, and economic activities diversified. To traditional industry and trade with distant lands was added the activity of the Barbary pirates, then in their golden age. Profits obtained from the trade in Christian slaves allowed the rulers to build sumptuous structures that revived the architectural heritage of the Middle Ages.