BEIRUT — A special peace envoy to Syria failed to win a cease-fire agreement after two days of talks with President Bashar Assad, but Kofi Annan left the country Sunday declaring he was optimistic that a peace process could take hold.

“It’s going to be tough. It’s going to be difficult,” the former United Nations secretary-general told reporters in Damascus, the Syrian capital. “But we have to have hope.”

Few outside observers expected that the veteran diplomat from Ghana would secure a quick breakthrough in the yearlong crisis, which has cost thousands of lives and resisted diplomatic remedies.

Opposition activists seeking Assad’s ouster criticized Annan’s trip before it began, labeling the visit another opportunity for the increasingly isolated government to buy time.

On Sunday, there was no concrete public indication that Annan’s talks had advanced chances for peace.

“I think the risk is just throwing envoys into Damascus without a clear-cut mandate and sufficient international backing for it,” said Peter Harling of the International Crisis Group, a Brussels-based think tank. “The regime for the time being sees no reason, no compulsion to change track.”

Annan, representing the United Nations and the Arab League, said he put forth concrete proposals, pressing Assad for humanitarian access to hard-hit areas and urging “an inclusive political dialogue,” the U.N. said.

Dialogue in Syria is a complicated issue, however, because many opposition activists say they won’t talk to Assad, whom they call a war criminal, and the president says he won’t engage “terrorists,” as he routinely calls the armed opposition.

“The situation is so bad and so dangerous that all of us cannot afford to fail,” Annan said.

The president backs any sincere effort to find a solution, the official Syrian news agency reported. But Assad also has said no political process can proceed while armed terrorist groups are spreading chaos.

Annan’s visit coincided with a government offensive in the restive northwestern province of Idlib that has left dozens of people dead in two days, opposition activists said.

Syrian authorities say terrorists have continued a campaign of killings, bombings and sabotage, assassinating a former boxing champion and an army colonel in the last two days.