Kenya's rival politicians signed a power-sharing agreement Thursday and shook hands after weeks of bitter negotiations on how to end the country's deadly postelection crisis.

Opposition leader Raila Odinga referred to his rival as "my countryman, President Mwai Kibaki" — an important sign of acceptance from a man who has said Kibaki's re-election in the Dec. 27 vote was a sham.

But in a reminder of the previous weeks' chaos, police fired tear gas to disperse dozens of people who were gathered outside Kibaki's office to witness the signing.

Kibaki and Odinga, both in blue suits, looked stoic as they signed the deal, side-by-side, to create the prime minister's post for Odinga that the opposition has been demanding.

"For the last two months, Kenyans have known nothing but sadness," Odinga said.

Kibaki added: "This process has reminded us that as a nation there are more issues that unite than that divide us."

Both Kibaki and Odinga claim to have won the country's presidential election, which observers say was marred by rigging on both sides.

The dispute set off street violence that killed more than 1,000 people and eviscerated the East African country's economy. Postelection violence has largely subsided in recent weeks, but the country remains on edge.

Mediator Kofi Annan said earlier Thursday that "compromise was necessary for the survival of this country."

As prime minister, Odinga will have the power to "coordinate and supervise" government affairs, according to the deal. That is more authority than the government had wanted to give, but it still leaves open whether the prime minister will have executive authority that cannot be overruled by the president.

It was unclear when Odinga would take up the position. Kibaki said he is reconvening parliament next Thursday to begin work on the constitutional changes necessary to make the deal into law.

In western Kenya, scene of the some of the worst postelection violence, many people said it will take years to recover.

"The deal between Raila and Kibaki will help to cool down the situation but I doubt if it will enable us to get back to our homes," said Paul Waweru, 56, among 19,000 people living in a camp in Eldoret.

Samson Kiplagat, a trader in the western town of Kericho, said Odinga had sold out.

"Raila has betrayed us for settling for a lesser position than that of the presidency," he said.

But residents in Nairobi's Kibera slum celebrated what they saw as a chance for peace.

"The general mood among people is that of happiness," said Nelson Ochieng, whose barbershop was destroyed during the postelection violence. "We are tired of the political crisis. I was a barber but my shop was burnt. Now I'm jobless and the end of this crisis means that I can rebuild my business."

The conflict has tarnished the reputation of this once-stable and prosperous country, bringing sharp rebuke from exasperated Western powers. Diplomats from the U.S. and around Africa have jetted in to Kenya to urge progress, many of the exasperated by the talks' glacial pace.

The State Department welcomed Thursday's announcement but said work remains to ensure long-term success.

"We want to see this agreement implemented and much will depend on its implementation," said Tom Casey, a State Department spokesman. "We will be watching very carefully to see how this progresses."

"We appreciate the goodwill shown" by Kibaki and Odinga in reaching the agreement and calling on their followers to cooperate, Casey added.

British Prime Minister Gordon Brown also applauded the deal but said "the hard work must continue. Kenyans need help to resettle and rebuild. Real leadership, patience and tolerance is necessary to ensure that the agreement sticks."