SAN'A, Yemen—President Ali Abdullah Saleh of Yemen agreed to step down on Wednesday after 33 years in power, becoming the fourth Arab leader swept away by protests this year and launching his violence-wracked country into a new era of uncertainty.

The president, who had steadfastly refused to sign a deal that would pave the way for his exit, made a surprise trip to Saudi Arabia, where he signed off on a deal to transfer power to Vice President Abed Rabbo Mansour Hadi within 30 days. The agreement...