HANGZHOU, China (Reuters) - U.S. President Barack Obama and Russian President Vladimir Putin had a longer-than-expected discussion on Monday about whether, and how, they could agree on a ceasefire deal in war-torn Syria, a senior U.S. administration official said.

Slideshow ( 5 images )

Obama and Putin spent about 90 minutes in a “constructive” meeting about getting humanitarian aid into the country, reducing violence, and cooperating on combating militant groups, the official told reporters.

In talks earlier on Monday, U.S. Secretary of State John Kerry and Russian Foreign Minister Sergei Lavrov were unable to come to terms on a ceasefire for the second time in two weeks, with U.S. officials stressing they would walk away if a near-term pact could not be reached.

Obama and Putin did not get into the finer details of a deal, but made progress to clarify “the remaining gaps” and directed Kerry and Lavrov to meet as early as this week to keep working on a deal, the official told reporters.

“If an agreement can be reached, we want to do so urgently, because of the humanitarian situation. However, we must ensure that it is an effective agreement,” the official said.

“If we cannot get the type of agreement we want, we will walk away from that effort.”

A cessation of hostilities agreement brokered by Lavrov and Kerry in February unraveled within weeks, with Washington accusing Syrian President Bashar al-Assad’s forces of violating the pact.

State Department officials have declined to elaborate on what the sticking points are preventing a deal, though the U.S. official said the remaining differences revolved around how the plan would be implemented.

Russia has insisted that it cannot agree to a deal unless opposition fighters, backed by the United States and Middle East allies, are separated from al-Qaeda linked militants they overlap with in some areas.

Obama and Putin also discussed the conflict in Ukraine - a crisis that Obama had earlier discussed with German Chancellor Angela Merkel and French President Francois Hollande.

The White House wants to determine whether the Minsk ceasefire can be implemented before Obama leaves office in January, or whether economic sanctions on Russia will need to be extended, the official said.