Image copyright Getty Images

How did a man who took office espousing a new era of engagement with the world end up a spectator to this century's greatest humanitarian catastrophe?

Barack Obama was not against using force to protect civilians. Yet he resisted, to the end, a military intervention to stem Syria's six-year civil war, even as it killed or displaced half the country's population, brutally documented in real time on social media.

Part of the answer to this vexing question has been clear from the beginning. President Obama was elected to end America's wars in Iraq and Afghanistan by a people tired of paying the cost in blood and treasure. He was extremely reluctant to get sucked into another messy Middle East conflict.

But when the siege and bombardment of cities like Aleppo placed the violence on the genocidal scale of atrocities set by Rwanda and Srebrenica, inaction by the US and its allies mocked the international community's vows of "never again".

Despite the pressing moral imperative, Obama remained convinced a military intervention would be a costly failure.

He believed there was no way the US could help win the war and keep the peace without a commitment of tens of thousands of troops. The battlefield was too complex: fragmented into dozens of armed groups and supported by competing regional and international powers.

Image copyright Reuters Image caption A boy pushes a wheelchair along a damaged street in the east Aleppo neighborhood of al-Mashatiyeh, Syria

"It was going to be impossible to do this on the cheap," he said in his final press conference of 2016.

But that was not the conclusion of some senior military and cabinet officials, nor did they even propose a mass ground deployment, according to former defence secretary Chuck Hagel.

They argued that a more limited engagement could have effectively tilted the balance of power against President Bashar al-Assad. Among the options: arming the rebels and setting up a safe zone from where they could operate early in the conflict, or military strikes on the Syrian air force to push Assad to the negotiating table.

Instead, the Obama administration focused on providing humanitarian aid, and on promoting a ceasefire and political negotiations aimed at Assad's departure.

"There is no military solution" became the mantra in briefing rooms at the White House and state department, but spokespeople were unable to explain how a political solution was possible without military leverage.

"If there is to be any hope of a political settlement, a certain military and security context is required," former CIA Director David Petraeus told a Senate committee last year. "We and our partners need to facilitate it, and…have not done so."

Obama's caution was reinforced by lack of support for military intervention from key allies such as the UK and Germany. That influenced his decision to back away from his famous "red line" threat of force in response to Assad's use of chemical weapons.

It was also part of a larger pessimism about what the US could achieve in the Middle East, sealed by a Nato intervention in Libya that was carefully planned but still left the country in a mess.

"The liberal interventionists seem to have forgotten that it is no longer the 1990s," wrote two of Obama's former national security officials, Steven Simon and Jonathan Stevenson, in October last year. "Disastrous forays in Iraq and Libya have undermined any American willingness to put values before interests."

Indeed, to fully understand President Obama's reticence, it is important to also understand that despite his liberal instincts and his soaring rhetoric about a more peaceful global order, he was a foreign policy realist with a keen sense of the limits to American power.

Although he campaigned to restore US moral authority after the disaster of the Iraq War, he rejected what he saw as the moralising interventionism of the president he replaced, George W Bush.

Instead, his emphasis was on measured diplomacy and progressive multilateralism.

That included a willingness to engage with repressive regimes, rather than consign them to an "Axis of Evil" - giving them "the choice of an open door", he told the Nobel Peace Committee when accepting its prize at the end of his first year in office.

Image copyright Getty Images

Above all, he was not willing to prevent humanitarian tragedies by expending American lives and military power unless he saw a direct security threat to the United States.

The agreement on Iran's nuclear deal is an example of this doctrine at its most effective.

Obama ably used diplomacy to force an issue around which there was a high degree of international consensus. He marshalled broad support for crippling sanctions, and then stretched out his hand to America's most enduring Middle East foe and negotiated an achievable deal - one that limited a threat rather than transformed a relationship.

Cuba also walked through that "open door", propelled by an economic crisis at home and drawn by a less hostile political climate in America, as did the junta in Myanmar.

Damascus did not. And Obama decided against trying to push it through.

US administrations have tended to bridge the gap between values and interests when the moral choice is also strategic. But Obama calculated early on that the Syrian civil war did not directly endanger America's national security.

Instead he focused US military might against the so-called Islamic State (IS), which he did eventually see as a threat to the homeland.

Again, he was able to organise an international coalition that has had considerable success in achieving a limited goal.

Image copyright Reuters Image caption Rebel fighters stand with their weapons on a military vehicle as they head towards the northern Syrian town of al-Bab

Dividing his Syria policy in two, however, meant inevitable contradictions. The White House held that the only way to stop the spread of IS was to end the rule and brutality of the Assad regime. But America's absence from the civil conflict served to strengthen the Syrian president.

Obama did grudgingly approve some covert military aid to moderate Syrian rebels to diffuse the power of Islamist fighters. But it wasn't enough to shape them into a force that could defeat Assad.

So the vacuum was filled by the better-supplied Islamist groups, feeding into Assad's narrative that the world had to choose between him or terrorists.

The presence of Islamist rebels, along with the momentum of the anti-IS campaign, also began to colour views of the regime within the administration, according to a US official who worked closely with these issues.

"Everything was done through a counterterrorism lens," he says. "This is a bunch of people who wanted Assad to stay because they were terrified of political Islamists taking over."

Obama argued that the regime's supporters, Russia and Iran, had more at stake in Syria than the US and would be prepared to fight harder to defend it. So any American intervention would only escalate the conflict. It's the same calculation he made in his approach to Ukraine.

Russia did enter the war to reverse rebel gains in 2015, turning the tide. Its anti-aircraft weapons closed the door on even the remote chance of a US intervention. Its air force solidified Assad's grip on Syria's cities, culminating in the military victory over Aleppo and giving Moscow new leverage in the Middle East while sidelining the US.

Many in the American foreign policy establishment believe Obama erred in defining US interests too narrowly in Syria.

"Syria exploded in strategic ways," says Vali Nasr, who's written a book arguing that the president's policies have diminished America's leadership role in the world.

"It empowered Russia and Iran, produced ISIS, strengthened al-Qaeda and created the refugee crisis which became a strategic threat to Europe."

Obama's critics have also faulted him for a detached, analytical leadership style they say is unsuited to geopolitical jousting.

"He wasn't good at brinkmanship, it wasn't his inclination," says Ian Bremmer, president of the political risk firm Eurasia Group.

Image copyright AP Image caption Secretary of State John Kerry talks with Russian Foreign Minister Sergei Lavrov in 2013

"I've always thought [George W] Bush was a leader who didn't like to think, and Obama a thinker who didn't like to lead."

Obama has taken the lead on combating what he sees as one of the biggest threats, climate change. And he hasn't hesitated from unilaterally ordering force when he felt America's security was at stake, as shown by his prolific use of drones against terrorist suspects.

But in Syria his administration left a perception of American weakness.

Stepping back from his red line on chemical weapons damaged US credibility, shaking the confidence of allies and, some argue, emboldening its adversaries.

"Some in the administration thought that the longer we continued to engage the Russians in a facade of ceasefire and political negotiations the more we were providing political cover to the regime and Russia and Iran as they continued to pursue a military victory," said the US official.

"It's hard to understand why the state department is going along with it," a European diplomat told me as the talks became about managing that victory. "It's supporting the Russian narrative."

Although Obama says he came to understand that very little is accomplished in international affairs without US leadership, he doesn't talk about it as a strategic asset, says Nasr.

That sets him apart from his predecessors who "believe US leadership is important for the world and important for America's hardnosed interests. Obama believes we can selectively lead where we have clear definable interests… but American leadership as a free-floating independent idea doesn't have value to him".

Despite the personality chasm between the cerebral lawyer exiting the White House and the reality TV star entering it, Barack Obama and Donald Trump are on the same page when it comes to non-interventionism.

Image copyright AP

In that sense, Trump's "America First" foreign policy is expected to be an extension of President Obama's.

But it would be a stripped-down version without Obama's attachment to international law and institutions or his moral commitment to universal rights, argues Max Boot, a fellow at the Council on Foreign Relations.

And although neither would seek foreign quarrels, Trump would be more disposed to "clobber anyone who messes with" the United States.

Would that make major powers such as China and Russia less likely to mess with America?

Boot suggests Trump's "menacing unpredictability" could be more effective than Obama's reasonable predictability in confrontations with Beijing. The President-elect's call with the Taiwanese president shows a penchant for brinkmanship that has certainly put China on alert.

Against these uncertain advantages, however, stand Trump's inexperience, his intemperate nature, and his hostility to some of the building blocks of US power, such as free trade in Asia.

Crucially, his uncritical support for Moscow, along with allegations that it has compromising information about him, have put America's Russia policy into uncharted territory.

Media playback is unsupported on your device Media caption Are Trump's nominees on the same page on Russia as their boss?

Some of the President-elect's key cabinet officials can be expected to try and temper his extreme impulses and outlier positions, while taking a more muscular approach than Obama.

In confirmation hearings, Trump's choices for secretary of state and defence advocated a conventional hard power policy, that included checking Russian moves on the geopolitical chess board.

But the nominee for top diplomat, Rex Tillerson, echoed Trump's hard line on China by proposing an unusually aggressive stance against Beijing, raising eyebrows and concerns amongst many lawmakers and diplomats.

History could very well judge Obama positively on Iran, Cuba and climate change. But the most important test of his foreign policy philosophy will be Syria, because it has been the crucible for the kind of realism he believes in.

He argues that he's saved the US from getting trapped in another disastrous Middle East war that would sap America's power. His critics charge he has diminished US power in a crucial region, and weakened American global leadership in the process.

The factor that shapes his legacy will be the same one that tests Trump: the extent to which either sustain, or reduce America's role in the world.