At this time the city was enclosed within lines of strong walls, which were washed by the sea on one side and protected by a wide trench on land. The Ottomans briefly gained control over Baku as a result of the  Ottoman-Safavid War of 1578–1590; by 1607, it came under Iranian control again. In 1604 Shah Abbas I () destroyed Baku fortress.