The Islamic State, which metastasized from a group of militants seeking to overthrow the Syrian government into a marauding army gobbling up chunks of the Middle East, gained momentum early on from a calculated decision by Syrian President Bashar al-Assad to go easy on it, according to people close to the regime.

Earlier in the three-year-old Syrian uprising, Mr. Assad decided to mostly avoid fighting the Islamic State to enable it to cannibalize the more secular rebel group supported by the West, the Free Syrian Army, said Izzat Shahbandar, an Assad ally and former Iraqi lawmaker who was Baghdad's liaison to Damascus. The goal, he said, was to force the world to choose between the regime and extremists.

"When the Syrian army is not fighting the Islamic State, this makes the group stronger," said Mr. Shahbandar, a close aide to former Iraqi Prime Minister Nouri al-Maliki, who said Mr. Assad described the strategy to him personally during a visit in May to Damascus. "And sometimes, the army gives them a safe path to allow the Islamic State to attack the FSA and seize their weapons."

"It's a strategy to eliminate the FSA and have the two main players face each other in Syria: Assad and the Islamic State," said Mr. Shahbandar. "And now [Damascus] is asking the world to help, and the world can't say no."

The Islamic State, also known by the acronyms ISIS and ISIL, has emerged recently as a major threat to the entire region and beyond. Its seizure of territory in neighboring Iraq triggered American airstrikes, and its execution this week of kidnapped American journalist James Foley prompted President Barack Obama to vow to continue the U.S. air war against the group in Iraq and to relentlessly pursue the killers. General Martin Dempsey, the chairman of the Joint Chiefs of Staff, said the group can't be defeated without choking off its operations in Syria.

This account of how the Islamic State benefited from the complex three-way civil war in Syria between the government, the largely secular, moderate rebels and the hard-core Islamist groups was pieced together from interviews with Syrian rebel commanders and opposition figures, Iraqi government officials and Western diplomats, as well as al Qaeda documents seized by the U.S. military in Iraq.

The Assad regime now appears to be shifting away from its early reluctance to engage the group.

In June, Syria launched airstrikes on the group's headquarters in Raqqa in northern Syria, the first large-scale offensive against the militant group since it rose to power a year ago. This week, Syria flew more than three dozen sorties on Raqqa, its biggest assault on the group yet.

The Syrian ambassador to Lebanon, Ali Abdel-Karim Ali, denied that Damascus supported the Islamic State early on and praised his government's battlefield response to the group, pointing to dozens of recent strikes on the group's headquarters.

"Our priorities changed as these groups emerged," Mr. Ali said in an interview at his office. "Last month it was protecting Damascus, for example. Today it is Raqqa."

Speaking of the Islamic State aggression that has decimated the more secular FSA, he said: "When these groups clashed, the Syrian government benefited. When you have so many enemies and they clash with each other, you must take advantage of it. You step back, see who is left and finish them off."

Mr. Shahbandar said the Islamic State's recent success forced the Syrian government and its Iranian allies to ramp up their military assaults, hoping the West will throw its weight behind Damascus and Tehran to defeat the extremists. Such cooperation would put the U.S. and its regional allies such as Saudi Arabia in an uncomfortable position, after years of supporting the FSA and demanding that Mr. Assad step down.

There are some signs that the opposing sides might be willing to work together. In Iraq, the U.S. began arming Kurdish Peshmerga forces this month, while the Iranians sent advisers.

The Syrian government facilitated the predecessor to the Islamic State—al Qaeda in Iraq—when that group's primary target was U.S. troops then in the country.

In 2007, U.S. military forces raided an al Qaeda training camp in Sinjar, northern Iraq. They uncovered a trove of documents outlining Damascus's support to the extremists, according to the U.S. Military Academy at West Point, which publicly released the records. The Sinjar records detailed the flow of extremists from across the Middle East to the Damascus airport.

Syrian intelligence agents detained the fighters as they landed in the capital, holding them at the Sadnaya military prison on the city's outskirts. If deemed a threat to the country, they would remain imprisoned, the records indicate. But if their intentions were solely to fight U.S. troops in Iraq, Syrian intelligence would facilitate their flow across the border, the records show. Making that journey were many Saudis and Libyans—the same nationalities that today bolster the ranks of the Islamic State.

Mr. Maliki's former spokesman, Ali Aldabbagh, said in an interview that he attended heated meetings in Damascus during which Baghdad asked Mr. Assad to stop the flow of al Qaeda militants across the border. He said Syria brushed off the requests.

"The Assad regime played a key role in ISIL's rise," said U.S. State Department spokeswoman Marie Harf at a news conference earlier this month. "They allowed for a security situation where ISIL could grow in strength. The Syrian regime fostered the growth of terrorist networks. They facilitated the flow of al Qaeda foreign fighters in…Iraq."

The Assad regime denies providing any support to the groups.

By the time the U.S. military withdrew from Iraq in December 2011, the militant group was nearly decimated. It regrouped in northeast Syria as the revolution was becoming a civil war. It was led by a charismatic figure from Samarra, Iraq, who goes by the name of Abu Bakr al-Baghdadi.

In May 2011, after the first protests broke out in Syria, the Syrian government released from the Sadnaya military prison some of its most high-value detainees imprisoned for terrorism, the first in a series of general amnesties. At least nine went on to lead extremist groups in Syria, and four currently serve the Islamic State, statements from the extremist groups and interviews with other rebels show.

Mr. Ali, the Syrian ambassador to Lebanon, said Damascus had released only common criminals in the amnesties, who were then offered money by extremist groups to fight against the government.

"When Syria released these people, they hadn't committed terrorist crimes," he said. "They were just criminals. In 2011, there were calls for freedom and accusations that Damascus was imprisoning people, so we hosted several amnesties [to demonstrate] our goodwill."

Bassam Barabandi, a diplomat in Syria's foreign ministry at the time who has since defected, offered a different explanation. "The fear of a continued, peaceful revolution is why these Islamists were released," he said. "The reasoning behind the jihadists, for Assad and the regime, is that they are the alternative to the peaceful revolution. They are organized with the doctrine of jihad and the West is afraid of them."

The U.S. has been reluctant to supply arms to the moderate rebels for fear that the weaponry would wind up in the hands of extremists.

By the start of 2012, radical groups were entrenched in the Syrian uprising, with al Nusra Front, al Qaeda's Syrian arm, the biggest player. Last year, Nusra split over an ideological and leadership struggle. Most of the group's foreign fighters formed what was then known as Islamic State of Iraq and al-Sham, or ISIS, since renamed Islamic State.

The split between Nusra and the Islamic State created a fissure among al Qaeda supporters. The Islamic State presented itself as truer to al Qaeda's past, with its more radical social codes, and was more focused than its predecessor in creating a caliphate, or Islamic empire.

The Islamic State militants despised the FSA and its largely secular rebels, denouncing them as nonbelievers. By last summer, the Islamic State began grabbing territory the FSA had captured from the regime. In September, the Islamic State defeated the FSA's Northern Storm Brigade in Azaz, a border outpost between Aleppo province and Turkey. The Islamic State quickly imposed its hard-line version of Islam, forbidding smoking, enforcing the segregation of the sexes and conservative dress.

The Islamic State continued to take territory and impose its social codes on more of Syria, growing more ruthless over time. In January, disparate rebel factions united to turn their guns on Islamic State fighters, while angry civilians simultaneously rose up against the group. The FSA drove the Islamic State from its strongholds across Syria.

Shifting alliances between various rebel groups made the situation murky.

In the northern city of Raqqa, Islamic State fighters were ensconced in three municipal buildings by mid-January, surrounded by rebels from the FSA and Islamic Front, a coalition of religious rebel groups. The Islamist militia Ahrar al-Sham, fighting alongside the FSA, posed the biggest threat, and Islamic State fighters appeared ready to surrender to that group.

"They got on the loudspeakers and said, 'We are your Muslim brothers. Don't kill us. Let us withdraw peacefully with our weapons,' " said Mohammed Abu Seif, an FSA rebel in Raqqa who was present at the standoff.

FSA fighters said their leaders wanted to continue the attack. They were prepared to kill the Islamic State militants, said Mr. Abu Seif and several other rebels involved in the fighting.

But Ahrar al-Sham wavered, they said, taking pity on their Muslim brethren. FSA fighters pressed on, hoping to wipe out the Islamic State and restore the secular roots of their revolution, according to Mr. Abu Seif and the other rebels.

But by the fourth day, Ahrar al-Sham started to withdraw from Raqqa. Rebels say a previously unreported deal was cut for Ahrar al-Sham and the Islamic State to swap territory. The Islamic State agreed to withdraw from Aleppo and Azaz, a border crossing with Turkey. In exchange, Ahrar al Sham would withdraw from Raqqa and Tal Abyad, another border town.

The FSA found themselves surrounded in the Raqqa suburbs by thousands of Islamic State fighters who were retreating from FSA advances elsewhere. On the eighth day, the FSA and its affiliates retreated, leaving Raqqa to the Islamic State.

By the spring, the Islamic State had used what amounted to a sanctuary in Raqqa to rejuvenate its ranks. With Raqqa as its base and headquarters, the militants went back on the offensive, storming across Syria, while its branch in Iraq did the same just across the border.

By June, Abu Bakr al-Baghdadi declared a caliphate and renamed ISIS the Islamic State, declaring nearly 12,000 square miles of contiguous territory across western Iraq and in Syria's north and east—an area the size of Belgium—a newly formed Islamic caliphate. The group now threatens the borders of Jordan, Saudi Arabia and Lebanon, where it briefly occupied a Lebanese border town this month.

Still, at times its actions appeared to help the Syrian government in its fight against the FSA. Aleppo, Syria's largest city, remained one of the few major strongholds of FSA resistance. Last month, the Islamic State quietly withdrew from the city's northeastern suburbs, clearing the way for Syrian government forces to stream in. Not a shot was fired. The gains enabled government forces to flank FSA rebels from three sides in Aleppo.

As FSA fighters struggle to hold off the regime, they also are fighting Islamic State militants in the countryside just north of Aleppo. Only 4 miles remain to fully encircle and besiege Aleppo. If FSA rebels lose the battle, it could spell the end of their revolution, rebels say.

Today, at a time when the FSA's ranks are thinning, new recruits from the Middle East and beyond are flocking to the Islamic State, crossing the Turkish border to settle themselves and sometimes their families in Raqqa. The group's fighters and core members are largely Syrians and Iraqis, but recruits are arriving from as far away as Europe and the U.S., say American intelligence officials. The U.K. chief of police in charge of counterterrorism estimated in June that 500 Britons alone have joined the group, although a member of British Parliament has said the number could be as high as 1,500.

At a recent U.S. intelligence briefing, American officials estimated the Islamic State's size to be about 10,000 before it took over Mosul, Iraq's second largest city, in June. European diplomats say the number may be as high as 20,000.

In June, after the Islamic State took over most of western Iraq and eastern Syria, controlling much of the border between the two countries, the Syrian regime began shifting its approach, striking Raqqa from the air. Since then, the Islamic State's appetite to attack the regime has grown, and it has assaulted government forces across Syria.

Iraqi officials say the strike on Raqqa may have been prompted by Baghdad's anger toward Damascus for allowing the Islamic State to rise to prominence in Syria, emboldening its Iraq branch.

Syrian civilians living in Raqqa and rebels said that unless the U.S. is willing to expand its military strikes against the Islamic State to include Syria, the group will continue to grow.