Yemen President Ali Abdullah Saleh has signed a deal to end his 33-year rule and hand over power to his vice president.