Until 1922, Ayvalık was almost entirely populated by Greeks. Anecdotal evidence indicates that, immediately after the defeat in the naval Battle of Chesma (Çeşme), the Ottoman admiral (later Grand Vizier) Cezayirli Gazi Hasan Pasha and his men from the ships who survived the disaster were lodged on their way back to the capital by a local priest in Ayvalık, who did not know who they were. Hasan Pasha did not forget the kindness shown to his sailors in the hour of need, and when he became Grand Vizier, he accorded virtual autonomy to the Greeks of Ayvalık, paving the way for it to become an important cultural center for that community in the Ottoman Empire during the 19th and early 20th centuries.