The new ruling came as President Yameen Abdul Gayoom moved to assert his power over the court, declaring a state of emergency and ordering security forces to raid the court compound where the justices were arrested.
Political turmoil has swept the Maldives since the surprise court ruling last week ordering the release of the opposition leaders, including many of Yameen's main political rivals.
The annulment of that order was announced in a court statement issued late Tuesday night after Yameen issued a state of emergency for the country that restricted citizens' rights and was internationally condemned. He also labeled the original court ruling a coup and a plot.
"This is not a state of war, epidemic or natural disaster. This is something more dangerous," Yameen said on national television. "This is an obstruction of the very ability of the state to function."
Yameen has rolled back a series of democratic reforms during his five years in office and said that the court overstepped its authority in ordering the politicians released, saying the order "blatantly disrupts the systems of checks and balances."
The emergency decree gives officials sweeping powers to make arrests, search and seize property and restrict freedom of assembly.
"This state of emergency is the only way I can determine how deep this plot, this coup, goes," Yameen said.
Meanwhile, Yameen's main political rival called on India to send an envoy - backed by its military - to free the imprisoned justices and opposition leaders.
Exiled former President Mohammed Nasheed, who was among the opposition politicians ordered freed and who is now in neighboring Sri Lanka, said in a statement that Yameen "has illegally declared martial law and overrun the state. We must remove him from power," calling for the Indian envoy and military to be sent. "We are asking for a physical presence."
He also called on the U.S. to stop Maldives government officials from making transactions through U.S. banks.
There was no immediate response from India or the United States, though both have called on Yameen to obey the original Supreme Court order.
The spokesman for U.N. Secretary-General Antonio Guterres said he was seriously concerned about the declaration of a state of emergency and the entry of security forces into the Supreme Court premises.
"The secretary-general urges the government of the Maldives to uphold the constitution and rule of law, lift the state of emergency as soon as possible, and take all measures to ensure the safety and security of the people in the country, including members of the judiciary," said the spokesman, Stephane Dujarric.
Yameen has cracked down on civil liberties since coming to power in 2013, imprisoning or forcing into exile nearly every politician who opposes him.
Hours after the emergency was declared, security forces in riot gear and blue camouflage stormed the Supreme Court building, arresting two judges, including Chief Justice Abdulla Saeed. It was not immediately clear what charges they faced, if any.
Security forces also arrested former dictator and opposition politician Maumoon Abdul Gayoom, who could be seen on cellphone video taken by his daughter being quietly escorted from his home, hugging friends and family and waving to supporters before being driven away.
His lawyer, Maumoon Hameed, said Gayoom faced charges including bribery and attempting to overthrow the government.
Gayoom was president from 1978 to 2008, when the Maldives became a multiparty democracy.
The Maldives is an archipelago of more than 1,000 islands with fewer than 400,000 citizens, more than one-third of them living in the crowded capital city, Male. Tourism now dominates the economy, with wealthy foreigners flown to hyper-expensive resort islands.
But it remains, in many ways, a small community. Gayoom, the former dictator, is the half brother of President Yameen. The two men are now political enemies. Nasheed, the opposition leader, unseated Gayoom in the country's first democratic elections in 2008. He and Gayoom are now political allies in an opposition alliance.
Nasheed resigned from the presidency following protests over the arrest of a judge. He lost the 2013 election to Yameen, then was convicted under Maldives' anti-terrorism laws in a trial widely criticized by international rights groups.
Nasheed said after last week's ruling that he would mount a fresh challenge for the presidency later this year.
China, Australia, the United States, Finland and Denmark updated their travel advice during the latest unrest. China urged people to avoid travel there and the others told citizens to be cautious.
While there was no immediate sign of India preparing to send troops to the Maldives, New Delhi does have a history of military involvement there.
In 1988, Sri Lankan militants working for a Maldivian businessman tried to take control of the country and seized many government buildings.
Then-President Gayoom asked for Indian military help to drive back the militants. India dispatched 1,600 paratroopers, who quickly restored Gayoom's control.
This version corrects that the Maldives Supreme Court has five members, not four.
Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.