Algeria's 82-year-old president has agreed to step down by the end of the month, bowing to weeks of protests and pressure.