Yemen's president was to sign an agreement on Saturday to quit power in a month's time in exchange for immunity, a deal rejected by street protesters demanding his immediate ouster and prosecution.

Ali Abdullah Saleh, who has ruled the impoverished Arabian Peninsula state for nearly 33 years, has in principle accepted the agreement negotiated by the six-state member Gulf Cooperation Council (GCC).

His departure would make Saleh the third ruler to be ousted by a wave of popular uprisings against autocratic Arab leaders that brought down the presidents of Tunisia and Egypt.

Saleh, a shrewd political operator considered a key U.S. ally against al Qaeda's Yemen-based wing, has forced mediators to split the signing ceremonies over two days by objecting to the presence of Qatari officials.

Qatar's prime minister was first to state publicly the Gulf deal would seek Saleh's resignation, and its satellite channel Al Jazeera has been blamed by Saleh for inciting revolt in the Arab world, which has been swept by pro-democracy protests.

So while the Yemeni leader signs the pact in Sanaa, his party's vice president will travel to the Saudi capital Riyadh for Sunday's official signing ceremony by the opposition.

Wave of protest

Tensions in Yemen have been ratcheted higher since gunmen shot dead 12 protesters in Sanaa on Wednesday and the opposition warned that violence could derail the deal.

Tens of thousands of protests took to the streets across Yemen on Friday, vowing to stay there until Saleh actually quit.

They also called for him to be put on trial for corruption and the deaths of the estimated 142 protestors killed since protest rallies began three months ago.

The GCC deal offers Saleh and his entourage, including relatives who run branches of the security forces, immunity from prosecution.

Friday's anti-Saleh protests in Sanaa ended in a funeral march for 12 protesters shot dead two days earlier, thousands passing their wooden coffins from hand to hand to their graves.

"The people want the trial of the murderer," some anti-Saleh demonstrators shouted.

Analysts say the 30-day window for Saleh to resign gives plenty of time for disgruntled forces from the old guard to stir trouble in Yemen, where half the population owns a gun and al Qaeda has gained a foothold in its mountainous regions.

The United States and neighboring oil giant Saudi Arabia want the Yemen standoff resolved to avert chaos that could enable al Qaeda's Yemen wing to operate more freely.

Should the deal go through, Saleh would appoint a prime minister from the opposition to head a transition government, which would set up presidential elections 60 days after he resigns.

Many protesters, already distrustful of the opposition coalition due its presence in the government in past years, called for them to back out of the deal.

"They wouldn't lose anything because Saleh isn't going to stick to the agreement. If he can't find a reason to overturn it he'll spark a war," said Sanaa protester Abdulsalam Mahmoud.