Luck had a lot to do with it. Luck and family put him in the right place at the right time, and he did the rest himself.
First, Saladin's uncle Shirkuh (Asad ad-Dīn Shīrkūh bin Shādhī) was a general serving Nur ad-Din (Nūr al-Dīn Maḥmūd Zengī), the second Zengid ruler of Aleppo (Syria). His father Zengi (Imad al-Din Zengi), founder of the Zengid Dynasty, had been the ruler of Aleppo and Mosul. On Zengi's death in 1146 (by non-political murder, at the age of about 60), his kingdom was divided between his oldest sons: his oldest son, Sayf al-Din Ghazi I, became ruler of Mosul (Upper Mesopotamia) and his second son Nur ad-Din got Aleppo. Sayf al-Din Ghazi I died a few years later, and another son of Zengi, Qutb al-Din Mawdud, became the new ruler of Mosul.
Fast-forward from the death of Zengi to 1163, in Egypt. The official ruler was the Fatimid Caliph Al-Adid (al-ʿĀḍid li-Dīn Allāh, AKA Abū Muḥammad ʿAbd Allāh ibn Yūsuf), then 12 years old and in the third year of his reign. As might be expected due to his age, he was a figurehead, with real power held by his vizier. (The previous Caliph had ascended to the throne at the age of 5 and died at the age of 11, and his predecessor at the ages of 16 and 21, so Al-Adid was the third child-caliph in a row.)
In 1163, the vizier Shawar (Shawar ibn Mujir al-Sa'di), who had become vizier the previous year, was overthrown and replaced by Dirgham (who had been his ally in his own coup 9 months earlier). Shawar fled.
Jerusalem (King Amalric I) attacked Egypt, due to non-payment of promised tribute. In response, Nur ad-Din attacked Tripoli to distract Jerusalem. Both attacks were unsuccessful. Shawar saw his chance, and asked Nur ad-Din for help. He got it, in the form on an army led by Saladin's uncle Shirkuh. Shirkuh (with Saladin coming accompanying him) invaded Egypt in 1164 to restore Shawar. Dirgham was killed in the fighting, and Shawar became vizier for a second time. Shawar rewarded Shirkuh by expelling him from Egypt and allying with Amalric. Shirkuh's army was on the eastern edge of the Nile delta, and Amalric's army arrived to besiege him there. This confrontation was settled by negotation (Amalric felt he had to leave to protect Antioch which was attacked by Nur ad-Din), and both armies left Egypt.
In 1166, Shirkuh (again, with Saladin coming along) invaded Egypt again. He was stopped by Shawar's alliance with Amalric - Amalric's army came to the "rescue". Amalric rescued Egypt from Shirkuh by occupying Alexandria and Cairo in 1167. Again, he had to leave due to Nur ad-Din, who attacked Tripoli.
In 1168, Amalric invaded Egypt again. In a reverse of the previous invasion, Shawar requested help from Nur ad-Din, who sent Shirkuh (and Saladin) back to Egypt. In 1969, Amalric was forced to retreat, and Shirkuh took control of Egypt. Perhaps rather fed up Shawar's behaviour, he had Shawar executed, and became vizier himself - nominally governor on behalf of Caliph Al-Adid, but in reality on behalf of Nur ad-Din. From Nur ad-Din's perspective, Syria and Egypt were now united against the Crusader states.
Shirkuh was not vizier for long - he died of illness (quinsy) two months later. Nur ad-Din chose a successor, but the caliph chose a different successor: Saladin. Different reasons for his choice of Saladin were reported, such as Saladin being young and powerless, or that Saladin, as a Kurd, would keep power out of Turkish hands (meaning Nur ad-Din's hands), or that the Zengid emirs in the army chose Saladin and forced Al-Adid to make him the new vizier.
1169 was an eventful year for Saladin. Not only did he become vizier, but he foiled an assassination attempt. This conveniently gave him an excuse to execute many of his high-ranking enemies. This immediately prompted a military revolt by part of the Fatimid army, which Saladin suppressed. Near the end of the year, there was another invasion of Egypt by Amalric, with help from Byzantium. Nur ad-Din sent reinforcements to help Saladin, and the invasion was defeated.
In 1170, the Emir of Mosul, Qutb al-Din Mawdud, died, succeeded by his second son, Saif ud-Din (Sayf al-Din Ghazi II) - the eunuch ’Abd al-Masish planned to rule as regent on behalf of Saif ud-Din. The first son, Izz al-Din (Izz al-Din Mas'ud), was quite displeased by this turn of events, and fled to Aleppo to get support from Nur ad-Din. Nur ad-Din had his eye on Mosul - and the opportunity to unite Syria, Upper Mesopotamia, and Egypt - and was happy to help. He took Mosul, and put Izz al-Din on the throne, leaving his own eunuch, Gümüshtekin, as governor and de facto ruler of Mosul.
Saladin was joined by his father and other members of his family, and he cemented his power by putting them into the government. In 1171, the caliph died. This was the end of Fatimid Shia rule - the Sunni Abbasid caliph was proclaimed as the new Caliph in Egypt, and Saladin became the sultan of Egypt. He was till a vassal of Nur ad-Din, but had firm control of Egypt even without Nur ad-Din's support.
In 1174, Nur ad-Din died of illness (again, quinsy reared its head). His 11 year old son, as-Salih Ismail al-Malik, became Emir of Damascus and Emir of Aleppo, as his successor. Gümüshtekin became the guardian of as-Salih and regent. Some of Nur ad-Din's other officers wanted the regency for themselves - there was trouble brewing. Meanwhile, Amalric took advantage of this to attack, but his only achievement was to die of dysentery. Jerusalem was out of the picture for the moment. Saladin vowed loyalty to as-Salih, and took his army to take control, officially on behalf of as-Salih. He succeeded, entering Damascus at the end of the year. To consolidate his power, he marrier Nur ad-Din's widow Ismat al-Din Khatun, and installed one of his brothers as governor. Gümüshtekin and as-Salih, in Aleppo, were not happy, and sent the Zengid army to retake Damascus in 1175. Saladin crushed it, and moved to take Aleppo. He failed to take Aleppo, but gained a truce (an alliance, even) with Gümüshtekin and as-Salih, and recognition of his rule over Damascus.
That's the story of Saladin's rise to power. Having used the resources of Egypt to take Syria, to take Jerusalem, his next step was to use the combined resources of Egypt and Syria to take Upper Mesopotamia. In 1181, the Emir of Mosul Saif al-Din died, and his brother Izz al-Din became emir for the second time. This was Saladin's chance, and he took a substantial army to make good use of it. He took Aleppo by negotiation after a short siege, and moved to Mosul. Unsuccessful! Mosul stayed out of his hands.
The next two parts of his story are well-known in the West: his capture of Jerusalem, and his fight against the Third Crusade.