It has to do with the informal alliance of Persian and Turkic sufi groups that helped form the Safavid dynasty. The Safavids emerged from the declining Timurid Dynasty in modern Iran. Ismail, the first Safavid Shah, started fighting in Azerbaijan near the turn of the 16th century. His unified disparate Persian/Turkic forces in order to fight the Timurid Turco-Mongols. However, the most important forces he unified were his native Safaviyya sufi order, which was Sunni, and the Qizilbash, which was a Shia Sufi militant order. As the leader of the Safaviyya and Qizilbash, Ismail was able to conquer Iran. At the same time, as he was the leader of the Safaviyya, he began adopting various Qizilbash, Shia practices and theories to the Safaviyya order. Eventually, he proclaimed Twelver Shia Islam as the state religion of his empire, which even put some pressure on the Qizilbash because they practiced a heterodox form of Shia Islam.
The Safavids ruled for about 240 years during which time Shia Islam remained the state religion and was promoted in the areas they conquered, notably Azerbaijan and modern eastern Iraq. They also supported Qizilbash in other areas (basically in the Ottoman Empire), which has led to the continued presence of groups like the Turkish Alevis and Bosnian Bektashis.
Due to the success of the Safavids, Iran was able to remain Shia even after the fall of the dynasty in the mid 18th century. For example, the Qajars were actually one of the Qizilbash groups that originally supported the Safavids, which helped continue the Shia identity of Iran after the short Afsharid interregnum between the Safavids and Qajars.