The two most important events in creating ISIS were the US-led invasion of Iraq in 2003 and the outbreak of the Syrian civil war in 2011. But to understand how all this happened, it helps to tell the story from the beginning.
Perhaps the place to begin this story is a quarter-century before ISIS formed, with the Soviet Union's 1979 invasion of Afghanistan, where Moscow sought to prop up the pro-Soviet regime that was under attack from rebels. Muslim foreign volunteers, seeking to repel the godless invaders, arrived to join the rebels (who called themselves the "mujahideen," which is just the correct Arabic word for "jihadis") — often backed by Saudi Arabia and by the US. Many of these fighters were Arabs who practiced an ultra-conservative version of Islam, rooted in and encouraged by Saudi Arabia, known as Wahhabism.
After the Soviet Union withdrew from Afghanistan in 1988-'89, many of the Arabs returned home, now veterans of combat who were ideologically hardened and infused with the belief that their faith in God had enabled them to defeat a superpower (not only had the Soviets withdrawn from Afghanistan, but the entire Soviet Union collapsed almost immediately after). Some of them, dedicated to a religious struggle they saw as global, formed al-Qaeda to continue the fight. They loathed both the brutal dictators ruling their home countries and the foreign powers that propped up these dictators while plundering the Middle East's resources. Al-Qaeda would in time declare war on them all.
Around this time, in the 1990s, a Jordanian man who fought in the Afghan jihad under the name Abu Musab al-Zarqawi founded an obscure terrorist group known as the Organization of Monotheism and Jihad. This would, several incarnations later, become the group that we today know as ISIS.