"I declare that I'm leaving power in order to have a free and transparent election in 90 days," said Compaore in a statement read out on television and radio stations. "For my part, I think I have fulfilled my duty."
Opposition protesters gathered in a square in the capital burst into cheers when they heard the announcement on hand-held radios.
Compaore, 63, said he decided to leave power "in light of the severely deteriorated sociopolitical situation and the threat of division in our national army and out of a desire to preserve the peace."
For months, an opposition coalition has been urging Compaore not to seek re-election for what would have been his fifth term in power. But Compaore and his ruling party looked set to push a bill through parliament yesterday that would have allowed him to run again.
Also Read
Determined to block the vote, protesters stormed the building, the vote was suspended and the military announced the legislature had been dissolved and a transition government would be formed. After that Compaore said he would lead until the new elections.
It was a dramatic turn of events for one of Africa's longest serving leaders who has survived other attempts to topple him.
Compaore first came to power following the October 1987 coup against then-President Thomas Sankara, Compaore's longtime friend and political ally who was killed in the power grab.
Compaore was elected four times since, though the opposition has disputed the results.
In recent years, he has fashioned himself as an elder statesman who brokered electoral disputes and hostage releases throughout West Africa. Domestically he kept a tight leash on any opposition and never groomed a viable political heir. In 2011, Compaore was confronted by an earlier challenge when multiple waves of protests washed over the country. At one point, mutinous soldiers occupied the palace, forcing Compaore to flee.