Gilani told a seven-judge bench headed by Justice Nasir-ul-Mulk that he could not even think of committing contempt of court as he had complete respect for the judiciary.
Explaining his government's position on the issue of asking Swiss authorities to reopen graft cases against Zardari, the premier said Pakistan's constitution gives full immunity to the President within the country and abroad.
Moreover, Presidents of all countries around the world too have immunity, Gilani pointed out in an extempore statement before the bench that lasted a little more than five minutes.
Gilani said his government was bound to act according to the Constitution and the law.
Gilani's lawyer Aitzaz Ahsan, one of Pakistan's leading legal experts, told the bench that the President enjoyed immunity under both the country's Constitution and the Vienna Conventions.
Ahsan further said the apex court should not force the government to write a letter to the Swiss government that becomes a joke, and creates a situation whereby the Swiss authorities say they cannot act against Zardari as he is protected by the Vienna Conventions.
The bench appreciated Gilani's decision to appear before the apex court.
Justice Asif Khosa, a member of the bench, said the premier's appearance in court showed the supremacy of law.
However, the bench questioned why the government had not acted on its past orders to reopen the cases of alleged money laundering against Zardari in Switzerland after the National Reconciliation Ordinance, a graft amnesty passed by former President Pervez Musharraf, was struck down in 2009.
Ahsan told the court that the current proceedings pertained to the contempt notice and he intended to argue that the premier had not committed contempt of court.
The reasons for not acting on the court's past orders could be explained by the Law Secretary, Ahsan said.
Top leaders of Pakistan's ruling coalition, including several federal ministers, gathered at the Supreme Court amidst tight security ahead of Gilani's appearance before the bench.
Among those who came to the court to extend support to Gilani were Foreign Minister Hina Rabbani Khar, Interior Minister Rehman Malik, Asfandyar Wali Khan of the Awami National Party, Chaudhry Shujaat Hussain of the PML-Q and Punjab Governor Latif Khosa.
Gilani was on Monday issued a contempt of court notice for failing to act on the apex court's order to reopen corruption cases against Zardari.
This is the third occasion that a Pakistani premier has been issued a contempt notice by the apex court.
The other premiers who faced similar action by the court were Zulfiqar Ali Bhutto and Nawaz Sharif.
Ahead of the court's proceedings beginning at 9.30 am, security agencies closed off the high-security Red Zone that is home to the Supreme Court and other buildings like the parliament and presidency.
Hundreds of policemen and parliamentary personnel were deployed in the area to create a three-tier security ring. The road in front of the apex court was closed at midnight.