LIMA (Reuters) - U.S. President Barack Obama said on Sunday that chaos in Syria could persist for “quite some time” and that Russian and Iranian support for President Bashar al-Assad’s air campaign had emboldened the Syrian leader’s crackdown on rebels.

“I am not optimistic about the short-term prospects in Syria,” Obama said at a news conference in Lima at the conclusion of a summit with leaders of Pacific Rim countries.

“Once Russia and Iran made a decision to back Assad and a brutal air campaign and essentially a pacification of Aleppo regardless of civilian casualties, children being killed or wounded, schools or hospitals being destroyed, then it was very hard to see a way in which even a trained and committed moderate opposition could hold its ground for long periods of time,” he said.

Obama, a Democrat who will be succeeded on Jan. 20 by Republican President-elect Donald Trump, said he told Russian President Vladimir Putin on the sidelines of the Asia-Pacific Economic Cooperation summit in Lima that he was deeply concerned about the bloodshed in Syria and that a ceasefire was needed.

“At this stage, we’re going to need a change in how all parties think about this in order for us to end the situation there,” Obama said, adding: “There’s no doubt that there will continue to be extremist forces in and around Syria because it’s still going to be in chaos for quite some time.”

Under Obama, the military aid program overseen by the CIA has given arms and training to moderate rebels in coordination with countries including Turkey, Saudi Arabia, Qatar and Jordan.

Trump has signaled opposition to U.S. support for the rebels, saying he wants to focus on fighting Islamic State. He has said he might even cooperate on fighting the militant group with Russia, Assad’s most powerful ally, which has been bombing the rebels for over a year in western Syria.

Obama’s trip to Peru was the last stop on an international farewell tour that included visits to Greece and Germany and was often overshadowed by questions about Trump’s election.

Obama said he had wrestled with the question of U.S. involvement in Syria for five years.

He said he concluded the United States did not have a legal basis for military involvement in Syria and that doing so would have been a “strategic mistake” given the effort to stabilize Afghanistan and Iraq and the need to fight Islamic State.