Fareed Zakaria examines the triumphs and struggles during President Barack Obama's time in the White House. Watch "The Legacy of Barack Obama" on Wednesday at 9 p.m. ET.

Washington (CNN) ISIS' march across Iraq and Syria -- a campaign that's forced President Barack Obama to return small numbers of US troops to the region, even after touting an end to the decade-long ground offensives there -- came as a surprise to US intelligence, the President told CNN in a new special report.

The terror organization's rise in a tumultuous Middle East has provided Obama some of the toughest decisions of his presidency, choices that CNN's Fareed Zakaria explores in "The Legacy of Barack Obama" airing Wednesday.

"The ability of ISIL to not just mass inside of Syria, but then to initiate major land offensives that took Mosul, for example, that was not on my intelligence radar screen," Obama told Zakaria, using the administration's term for the Islamic State terror group.

As Obama's presidency concludes, it's clearer than ever he'll depart the White House with Syrians facing nearly unyielding misery.

The city of Aleppo has become a nightmare for the tens of thousands of Syrians still living there, short on food and medical supplies as cold winter weather sets in. The conflict has led to hundreds of thousands of deaths, spurred a destabilizing refugee crisis in Europe, and led to the rise of a terror group that Obama admits he didn't see coming.

It's a legacy he says haunts him, but as he explains to Zakaria in Wednesday's special, the decisions he did make were the best he could muster in a country with no good choices.

Avoiding a large scale ground conflict in Syria "is the smartest decision from a menu of bad options that were available to us," he told Zakaria for the special, which airs at 9 p.m. ET on CNN.

In interviews with Obama and those who worked in his administration during the early days of the Syrian conflict, a picture emerges of a president conflicted about how best to avoid the bloody reality that eventually emerged.

JUST WATCHED CNN on the ground in war-ravaged Aleppo Replay More Videos ... MUST WATCH CNN on the ground in war-ravaged Aleppo 03:10

He ran for office vowing to end large-scale troop deployments in Iraq and Afghanistan, sensing the American people were war-weary after a decade of combat. He fulfilled his promises by the time he came up for reelection in 2012, giving him a campaign trail talking point that helped him defeat Republican rival Mitt Romney.

In Iraq, Obama's withdrawal plan was hastened by the expiration of an agreement signed in 2008 by President George W. Bush allowing US troops to remain in the country. Some of Obama's generals wanted to keep 10,000 US troops in Iraq to maintain stability in the country as it emerged from a decade of war. But negotiations between Washington and Baghdad on extending the agreement fell apart when then-Iraqi Prime Minister Nouri al-Maliki refused to agree to the Obama administration's terms.

Some have accused Obama of failing to press hard enough for a new "status of forces agreement." On Tuesday, Obama argued it wouldn't have made a difference in preventing the rise of ISIS.

"Maintaining American troops at the time could not have reversed the forces that contributed to ISIL's rise: a government in Baghdad that pursued a sectarian agenda, a brutal dictator in Syria that lost control of large parts of the country, social media that reached a global pool of recruits, and a hollowing out of Iraq's security forces," Obama said during remarks at MacDill Air Force Base in Florida.

The decision to remove all US troops from Iraq provided Donald Trump with a rhetorical bludgeon during this year's presidential campaign. He accused Obama and Democratic challenger Hillary Clinton of leaving a power vacuum in Iraq that allowed ISIS to take hold.

It's an assessment that's impossible to prove right or wrong. Obama's top military advisers express doubt that keeping a residual force of US troops would have prevented ISIS' rise.

"I don't know whether 10,000 troops would have given us the leverage. I suspect it might not have. But I would have liked to have tested the proposition," said David Petraeus, who served as commander of US Central Command and of US forces in Afghanistan under Obama before becoming CIA director. He's now under consideration for a role in Trump's administration.

In neighboring Syria, another crisis was unfolding as President Bashar al-Assad began a brutal assault on opposition forces. Assad's crackdown drew jihadists from Iraq, where the al-Qaeda affiliate morphed in the terror group now known as ISIS.

Obama viewed the crisis dimly. He was skeptical the opposition forces there were large or organized enough to amount to a real challenge to Assad's regime -- even as his advisers recommended arming moderate rebels.

"There was a time and there was a way to help moderate in the opposition prevailed," said Robert Ford, the US Ambassador to Syria from 2010 to 2014. "Absolutely we missed an opportunity."

It wasn't until Assad crossed his self-declared "red line" of deploying chemical weapons on civilians that Obama began ordering his military to prepare for a military strike in Syria. But he backed away from ordering the mission, asking for support from Congress that never came.

Some viewed the move as backing away from a firm commitment to respond to a horrific crime against civilians, including children. Obama argues his approach to instead help broker a deal that ridded Assad of his chemical weapons stockpiles, was a smarter approach.

"We, in fact, positioned our military to be able to strike Assad if he did not give up his chemical weapons," Obama told Zakaria. "And the fact is, he got rid of his chemical weapons in an unprecedented way."

But the civil war continued to rage, and ISIS began taking ground. It established Raqqa, in northern Syria, as its capital. And it began moving into Iraq, including in cities with names well-known to Americans -- Mosul, Fallujah, Ramadi, the cites of key battles during the Iraq War.

"When you have these ungoverned spaces, that's exactly where extremist like to go to setup," said Ford. "They can plan. They can organize. They can recruit. They can do training. That's what they need."

The US, along with a 60-nation coalition, has been pounding the group with airstrikes for more than two years, and US special operators have worked to train and assist Iraqi Security Forces and vetted rebel groups in Syria.

The efforts have squeezed ISIS on the battlefield, reducing its territory and taking out key figures in its leadership. A campaign to retake Mosul, the group's base in Iraq, is making progress.

But the wins on the battlefield haven't stopped the group from spreading their hate abroad. Attacks in Paris, Brussels, Nice, San Bernardino, and Orlando all had varying degrees of ISIS links, leading to new terror fears a decade-and-a-half after September 11, 2001.

Obama has insisted the US is safer, noting that a large-scale attack like the one of the World Trade Center and the Pentagon hasn't transpired while he's been in office.

In a region with few good choices, he says there's little any president could have devised that would have made much of a difference.

"Have we been flawless in the execution of what is a complicated policy in the region? Absolutely not. I think flawless is not available when it comes to foreign policy or the presidency, at least with mere mortals like me at the helm," he told Zakaria. "But have we made, I think, the best decisions that were available to us, at each stage? The answer is yes."