In 1742 Shamakhi was taken and destroyed by Nader Shah of Persia reincorporating it back to Iran, and, who, to punish the inhabitants for their Sunnite creed, built a new town under the same name about 26 kilometers to the west, at the foot of the main chain of the Caucasus Mountains.