The Safavid Empire traces its origins back to the early 14th century. Their dynasty came out of a religious background. It was founded by a man named Safi al-Din (it was from his name that "Safavid" came). Safi al-Din founded an order of Sufis at that time. Sufism is a mystical form of Islam.
The Safavids were different from other Muslim dynasties of their time because they were Shi'a rather than Sunni. This was one of the things that set them apart from people like the Ottomans and helped to cause conflict between them and the Ottomans.
In the early 1500s, the dynasty moved out of Azerbaijan. It became an empire that was based in Persia and came into conflict with the Ottomans in the west.
The Safavids were founded as a Sufi order, called the Safaviyya, in Azerbaijan. They were composed of Kurds and Azeri Turks who intermarried with Georgian, Circassian, and Greek people. Their order was founded by Safi al-Din (1252-1334), a mystic who adhered to the Shafi'i school of jurisprudence of Sunni Islam. Later on, his descendants imported some ideas borrowed from Shi'ite Islam, so that over time the Safavviya became Twelver Shi'ites (believers in the existence of twelve successors to the Prophet Muhammad).
The brotherhood gained power through marriage and as warlords joined it. By the 15th century, it had become a military group that waged a holy war against what is now Turkey and Georgia. In 1501, led by Shah Ismail I, it conquered Iran and imposed Shi'ism on the country. The Shi'ism of the Safavids was previously somewhat unorthodox, containing some untypical beliefs about the spiritual status of its own leaders. However, when Shah Ismail came to power, he imported clerics from Syria and Lebanon to impose more orthodox Shi'ite beliefs and practices in Iran. In 1501, the Ottomans outlawed Shi'ism in their lands. As a result, many Ottoman soldiers fled to the Safavid empire, thereby strengthening it.