The Supreme Court ruled he had “ceased to be the prime minister of Pakistan”.
In April, the Supreme Court convicted Mr Gilani of failing to pursue corruption charges against President Asif Ali Zardari.
The legal case is part of a bitter feud between Pakistan’s civilian government and the judiciary.
In April, Mr Gilani was given only a token sentence and spared a jail term.
Tuesday’s court ruling disqualified him from office and from parliament.
“Since no appeal was filed [against the 26 April conviction]… therefore Syed Yousuf Raza Gilani stands disqualified as a member of the Majlis-e-Shoora [parliament],” Chief Justice Iftikhar Chaudhry told a packed courtroom.
He added: “He has also ceased to be the prime minister of Pakistan… the office of the prime minister stands vacant.”
The court backdated the disqualification to 26 April, raising questions over decisions Mr Gilani has made in office since then – including the budget.
Amid the uncertainty, Pakistan’s main stock market fell slightly by close of business on Tuesday.
It is not clear what next steps Mr Gilani may take – or whether his removal means the fall of the government.
Senior leaders of the governing Pakistan People’s Party (PPP) are in emergency session with Mr Gilani and President Zardari, reports the BBC’s Orla Guerin in Islamabad.
A government official said President Zardari had also summoned heads of the PPP’s coalition partners to the presidency for further talks.
The party has the necessary majority in parliament to elect a successor to Mr Gilani.
Our correspondent says there will be great political uncertainty following the ruling, and some people will see it as another round in the clash of institutions taking place in Pakistan.
During Tuesday’s hearing, Attorney General Irfan Qadir accused the court of behaving unlawfully.
He said the prime minister was not answerable to the court in regard to his professional duties and that justices had violated an article of the constitution in their ruling.
Mr Gilani has always insisted only parliament can remove him from office.
He decided not to appeal against the contempt conviction in April – his lawyer saying he feared a more unfavourable decision from the court if he did so.
The pursuit of the contempt case by Supreme Court judges is widely seen as an attempt at meddling in the country’s politics. Many believe the judiciary is being backed by the military.
The charges against President Zardari date back to the 1990s when his late wife Benazir Bhutto was prime minister. They were accused of using Swiss bank accounts to launder bribe money.
President Zardari has always insisted the charges against him are politically motivated.
The Supreme Court ordered Mr Gilani’s government to write to the Swiss authorities to ask them to reopen the cases against Mr Zardari.
But Mr Gilani refused, saying the case had been closed by a Swiss judge “on merit” and the president had constitutional immunity.