Malawi's High Court has rejected a decision by President Joyce Banda to annul this week's general election - in which she was a candidate.
Ms Banda had earlier said Tuesday's vote had been marred by rigging, multiple voting and computer-hacking.
She said a new vote should be held within 90 days but she would not stand again in any new poll.
However, the head of the electoral commission said the president did not have the power to annul the vote.
The High Court made its ruling after the commission said that despite problems involving the electronic transmission system, the poll remained valid and vote-counting would go on.
Malawi's election was chaotic, with one BBC correspondent reporting people voting two days on from election day because of delays in distributing polling material.
Frustrated voters set one polling station alight and smashed election material at another.
In some places, voting boxes or lids did not arrive so officials used buckets and plastic wrap.
Late on Friday, the Malawi Electoral Commission (MEC) said Joyce Banda's rival candidate Peter Mutharika had taken a lead of 42%, with 30% of votes counted. Ms Banda was in second place with 23%, the commission said.
"I am nullifying the elections, using the powers invested in me by the Malawi constitution," Ms Banda told a news conference.
"I want to give Malawians an opportunity to choose a candidate of their choice in a free and fair manner. When elections are to be held again, I will be stepping aside," she added.
Mrs Banda had previously accused a party, which she did not name, of infiltrating and hacking the electronic system, which transmits the results to the electoral commission's headquarters.
The MEC's chairman denied that its system had been hacked.
In a previous statement about the elections, Mrs Banda had said that irregularities included
- The arrest of presiding officers who were "caught in the act of rigging"
- Some people voting up to three times
- "Serious anomalies" where some candidates won more votes than the number of registered voters
- Discarded and tampered ballots
- Communication devices of some monitors being blocked
Around 7.5 million people were eligible to vote in the fifth elections since the end of one-party rule 20 years ago.
This was the first time that Malawi held presidential, parliamentary and local elections on the same day.