Last week, a self-described heir to the Prophet Muhammad declared himself the supreme leader of a new Islamic state stretching from eastern Syria to northern Iraq. How did Abu Bakr al-Baghdadi, the nom de guerre of a mediocre Iraqi religious scholar in his mid-40s, outmaneuver al Qaeda as the new vanguard of jihadist ideology? How did he and his followers—armed with Kalashnikovs, smart phones and their ominous black banner—so suddenly take over the campaign to rid the Muslim world of Western and secular influence?

The rise of Mr. Baghdadi and his newly proclaimed "caliphate" highlights what had been a closely held secret of the Sunni jihadist movement: a split in the ranks that had been festering for years. It pits a new generation of shock troops hardened by battle in Iraq and Syria against al Qaeda veterans who had built the movement but were increasingly seen as too passive, both politically and theologically.

Mr. Baghdadi's proclamation was stunningly brazen. The leader of a faction of puritanical Sunni militants who have plagued Iraq with suicide bombings and beheadings, he was long considered a relatively inconsequential cog in the larger al Qaeda machine. Few people outside jihadist circles had heard of him, let alone seen him, before last month, when his followers in the militia known as the Islamic State of Iraq and al-Sham, or ISIS, rolled across northern Iraq, conquering Mosul, one of the largest cities in the country. Then on July 4, Mr. Baghdadi emerged at Mosul's al-Nuri Grand Mosque, promising to restore to his Sunni brethren their "dignity, might, rights and leadership," according to a video of the sermon distributed by his group.

Mr. Baghdadi's military offensive has startled the U.S. and its Middle Eastern allies, who fear that it portends prolonged regional instability and terrorist attacks far afield from Iraq. Yet for the man leading what he now calls simply the Islamic State, the latest campaign has meant more than territorial conquest. Mr. Baghdadi's victories also mark the crescendo of a 10-year theological battle between veterans of al Qaeda, the core organization started by Osama bin Laden in the 1980s and now led by the Egyptian-born extremist Ayman al-Zawahiri, and its rebellious affiliate in Iraq, which Mr. Baghdadi took over in 2010. The prize: purported leadership of the world's estimated 1 billion Sunni Muslims and of a jihad supposedly waged in their name.

The rupture between Mr. Zawahiri's old guard and Mr. Baghdadi's new guard escalated last year, when Mr. Baghdadi refused Mr. Zawahiri's demand to formally declare his obedience and instead called the al Qaeda leader's rulings antithetical to God's commands. It was an audacious snub within the puritanical circles of al Qaeda and its fellow travelers. It was also the start of a slow-moving coup against the established jihadist hierarchy.

Today's strains flow from decades of wrangling over Islamist doctrines of religious and political revolution. In the 1940s and 1950s, during heady days of nationalism and rebellion in the Middle East, the Egyptian writer Sayyid Qutb —widely considered the father of contemporary jihadist thought—merged Quranic verses, Islamic prophecies and Third World revolutionary fervor to produce a seminal tract advocating Islamist political violence.

The early jihadist intelligentsia that adopted Qutb's views included a young Saudi named Osama bin Laden and other members of a fringe movement called Salafism, which holds that Muslim society should adopt a governing and religious framework that adheres to Muslim practices from the early days of Islam's founding in the seventh century. Those who espouse using violence to achieve such a puritanical state are known as Salafi jihadists.

Among the followers of this creed, the battle between Mr. Zawahiri and Mr. Baghdadi is a pivotal development. "Like the old saying goes: The revolution devours its own," says Jérôme Drevon, a fellow at the Swiss National Science Foundation who specializes in Islamist movements. "What we are seeing is a generational split between older jihadis who have learned pragmatic lessons [of overreach]…and a younger, more brutal generation who don't believe in or haven't lived long enough to learn those lessons."

Al Qaeda (which is Arabic for "the base") had significant though limited ideological appeal and recruiting power throughout the 1980s and 1990s. Its charismatic leader, bin Laden, recruited Arab radicals and others to fight the Soviet occupation of Afghanistan. He also turned his sights on what he considered impure and impious Arab tyrannies—above all in his native Saudi Arabia, home of Islam's two holiest cities, Mecca and Medina.

Bin Laden also broadened his scope to target the U.S. and the West, which al Qaeda came to call "the far enemy" for propping up Israel and Arab autocrats such as the Saudi royal family and Egypt's Hosni Mubarak. Al Qaeda's allure was strengthened by its spectacular Sept. 11, 2001, terrorist attacks and by satellite television and Internet technology that spread its message across the globe.

The group's brain trust had always relied on a division of power between the ideologues—such as Mr. Zawahiri, an Egyptian physician who grew up in the 1940s and 1950s alongside Qutb and his followers—and the executives like bin Laden and his military chiefs, who secured the money, inspired the recruits and perfected the bombs and the battle tactics.

Mr. Zawahiri honed al Qaeda's basic tenets. He declared that the world, including most Muslim societies, languished in a state of impurity and that it was al Qaeda's religious duty to cleanse it. The main culprits, according to Mr. Zawahiri's teachings, were the secular West and its Arab allies, both marked as primary targets in al Qaeda's holy war.

After 9/11, the U.S. and its partners drove al Qaeda out of its haven in Taliban-ruled Afghanistan and weakened its operational abilities. Mr. Zawahiri also became vulnerable to criticism from an even more fanatical end of the jihadist spectrum over a doctrinal issue that lies at the core of the Salafi quest to build a pure Islamist state.

The dispute centers on Mr. Zawahiri's belief that a caliphate—a state that can demand allegiance from all Muslims and declare jihad against the enemies of the faith—can emerge only after the wider Muslim world has been purified. Mr. Zawahiri hopes to bring Muslims out of their unredeemed state of jahiliyya—the type of spiritual ignorance that existed before the Prophet—by excising all contact with corrupting Western influences and placing governing institutions in the hands of administrators who share this vision and can promulgate it to the mass of Muslims.

This religious interpretation was shared by the Taliban leader Mullah Mohammad Omar—which is why al Qaeda didn't declare a caliphate when the Taliban seized control of Afghanistan in the 1990s, according to Hassan Abu Hanieh, a Jordanian scholar and former Salafi who is an independent expert in Islamist groups. "A caliphate has to be based on the consent of the public," Mr. Abu Hanieh said. "Afghan society was at war, and thus, according to [al Qaeda's] religious understanding, the time was not right for this desired goal."

But Mr. Baghdadi and his followers reject this doctrine of an evolving religious and social consensus. They believe instead that a pure Islamic regime can be more swiftly imposed by force. This basic split has existed for a decade between al Qaeda and its one-time offshoot in Iraq, which formed after the U.S. invaded in 2003 and helped establish the first Shiite government in Iraq in centuries.

The doctrinal dispute first came to light in the mid-2000s in a set of letters that bin Laden and Mr. Zawahiri wrote to Abu Musab al-Zarqawi, the infamous founder of al Qaeda in Iraq—a Jordanian responsible for a wave of beheadings, bombings and kidnappings. Bin Laden, in hiding after fleeing Afghanistan after 9/11, scolded Zarqawi for attacks that targeted Iraq's majority Shiites and shed Sunni blood as well. Such tactics, he argued, divided Muslims, alienated many Iraqi Sunnis and diverted efforts away from al Qaeda's focus on killing Americans and toppling heretical Arab regimes.

But to Zarqawi and his followers, killing anyone who rejected their puritanical views—including Shiites or even dissenting Sunnis—was a step toward purity. They chafed at bin Laden's reprimand, but they didn't break ranks. Zarqawi formally pledged bay'a—or obedience—to bin Laden, effectively papering over the ideological division.

By the late 2000s, however, U.S. forces had killed Zarqawi, and the Iraqi offshoots of al Qaeda had gone through several incarnations. By then, Mr. Baghdadi had appeared on the scene. After years of imprisonment by the U.S., he joined what was then known as the Islamic State of Iraq, or ISI. The group had published a pamphlet titled "The Birth of the Islamic State Declaration," reasserting its belief that Muslims had a holy duty to create—by force if necessary—the conditions that would allow a caliphate to re-emerge.

In many ways, the doctrinal differences among Salafi jihadist factions mirror the dispute that raged among Russian communist factions at the start of the 20th century. The two major factions—the Mensheviks and the Bolsheviks, led by Lenin —split over the basic question of the party's role. Should it work to develop the social consciousness that would move humanity toward a perfect workers' state, or should it try to bring about such change immediately through violent revolution?

"Every radical movement has its wings, its pragmatists and its puritanical firebrands," said Haras Rafiq, a counterterrorism adviser for the U.K. government and a scholar at London's Quilliam Foundation, which seeks to counter Islamist extremism.

Lenin supported the path of aggressive force and outflanked his Menshevik opponents politically after 1903. By 1918, he had solidified his rule over the communist movement by leading it to victory over Czar Nicholas II's dying empire.

Mr. Baghdadi's rise to power mirrors Lenin's in its efficiency and brutality. By 2010, Mr. Baghdadi—whose main success up until that time was winning a doctorate in religious studies from a mediocre Iraqi university—had taken over ISI. After U.S. forces killed bin Laden in May 2011, Mr. Baghdadi gave up any pretense of unity with al Qaeda. His followers swore allegiance to their own leader, not to Mr. Zawahiri, bin Laden's successor and longtime deputy—a stinging show of defiance.

Mr. Baghdadi spent the next few years locked in ideological battles with Mr. Zawahiri, especially after 2011, when Sunni jihadists began to join the worsening civil war in Syria. Tension mounted in September 2013, when Mr. Zawahiri issued a pamphlet called "General Guidelines of the Work of a Jihadist," codifying al Qaeda-approved rules of warfare. It circumscribed religiously sanctioned killings.

But followers of Mr. Baghdadi continued to insist that anyone who disagreed with their movement's harsh interpretation of Islam could be labeled an apostate—a practice used to justify the group's decadelong practice of killing Shiites and fellow Sunnis who rejected its views. As the struggle against Syrian President Bashar al-Assad —the leader of a dictatorship dominated by Alawites, a small sect descended from Shiite Islam—grew bloodier, Mr. Baghdadi rebuffed Mr. Zawahiri's treatise as incompatible with the war he was fighting in Syria and across the border in Iraq.

The power struggle finally came to a head on April 9, 2013, when Mr. Baghdadi launched his first outright rebellion against al Qaeda. In an audio recording released online, he declared a hostile takeover of the Nusra Front, a Syrian jihadist rebel militia linked to al Qaeda whose leader had pledged allegiance to Mr. Zawahiri. Mr. Baghdadi declared that the two groups would merge under a single name: the Islamic State of Iraq and al-Sham, or ISIS.

Sunni jihadists were jolted by the move. The Nusra Front immediately rejected Mr. Baghdadi's takeover bid and refused to swear allegiance to him. In June, Mr. Zawahiri released a three-page letter intended to extinguish "the fire of sedition" ignited by Mr. Baghdadi. In the missive, Mr. Zawahiri ordered Mr. Baghdadi to retreat from Syria while retaining control of the jihadist project in Iraq. But in a reply disseminated through the Internet, Mr. Baghdadi not only refused to retreat but also said he had "chosen the command of God over the command in the letter [by Mr. Zawahiri] that contradicts it."

Al Qaeda's old guard was outraged at this affront to their gray-bearded leader. For months, several elders of the movement had tried to reconcile Mr. Baghdadi to the larger al Qaeda group—to no avail. On Feb. 3, Mr. Zawahiri formally disowned ISIS, and later that month, Mr. Zawahiri's personal emissary to mediate the Syrian struggle was killed by a suicide bomber. Syrian rebels accuse ISIS of the murder, a charge that the splinter group denies.

By spring, Mr. Baghdadi was in full ascent, sweeping aside al Qaeda's sanctimoniousness with tangible military gains. His forces solidified control of a swath of Iraqi territory, and he prepared to launch a high-profile operation to recruit others to his doctrinal and political views. His forces stunned the region by conquering Mosul and marching south toward Baghdad.

Mr. Baghdadi's expanding empire, which includes control over some of Iraq's prime oil facilities, has put al Qaeda on the back foot—and left the U.S. and its allies worrying about the security threats that could emerge from this new, virulent form of jihadism. The chunk of territory that Mr. Baghdadi's followers have carved out of Iraq and Syria affords them a haven in which to train and plot—one that, unlike pre-9/11 Afghanistan, lies at the heart of the Arab world and close to Europe and Israel.

Some intelligence officials fear that this new competitor to al Qaeda could redouble its attempts to launch a spectacular terrorism attack in Western Europe or the U.S. On Tuesday, Attorney General Eric Holder warned that the danger that radicalized Westerners could return home from Syria's civil war to plot terrorist attacks now amounts to "a global crisis."

Meanwhile, the aftershocks from the jihadist rupture are still reverberating. Since Mr. Baghdadi's sermon last week declaring himself caliph, al Qaeda affiliates in Yemen have denounced him. So too has the mainstream Sunni religious establishment, including Cairo's al-Azhar seminary, which has always opposed al Qaeda's actions, and Yussuf al-Qaradawi, an Egyptian cleric widely seen as the spiritual leader of the Muslim Brotherhood.

But it is still unclear what effect, if any, such censure will have on the audience that Mr. Baghdadi has shown himself adroit at cultivating: the younger Islamist radicals, including dozens of European Muslims, who have been flocking to him.

"There is a wellspring of disillusioned Muslims in Western Europe vulnerable to radicalization" by the Islamic State, says Richard Barrett, the former head of counterterrorism for MI6, the U.K.'s foreign spy agency, and now an adviser at the Soufan Group, a private counterterrorism consulting firm. "They are looking for a leader who doesn't sit back and cogitate but who acts on his beliefs, who understands their feelings of marginalization"—a leader who offers "promises of greatness."