Supporters of cleric Tahir-ul-Qadri gather at an anti-government march in Islamabad. (AFP Photo)
"If you and the army come face to face, don't raise your hand. If you do, you will not be welcome amongst us," he said.
Legislators left by a back entrance. Lawmaker Marvi Memon, from the ruling party, said every parliamentarian present had denounced the protests and offered support to the government.
"This affront to parliamentary democracy has been noted," she said. "This is only a handful of people and they do not represent the will of the people."
Parliament would reconvene on Thursday, she said.
Read: Islamabad on edge as Imran Khan, Qadri supporters reach Parliament
The military, which often acts as an arbiter when it is not ruling directly, broke its silence to call for a political solution to the crisis.
"(The) Situation requires patience, wisdom and sagacity from all stakeholders to resolve (the) prevailing impasse through meaningful dialogue in (the) larger national and public interest," military spokesman General Asim Bajwa tweeted as the protesters approached parliament.
Last month, the civilian government made the military officially responsible for the security of top government offices. All the protesters have been careful not to offend the military, which is Pakistan's most powerful institution.
One of the country's other power centres is the activist judiciary, which waded into the fray on Wednesday when Chief Justice Nasir ul-Mulk summoned Khan and Qadri to appear on Thursday over a petition filed against their protests.
Cleric Tahir-ul-Qadri shows the victory sign on his arrival at an anti-government march in Islamabad. (AFP Photo)
Pakistan's top courts can declare an interest in any case or accept a complaint from any petitioner. They can also charge those who question their decisions with contempt of court.
Khan wants Sharif to step down because he believes the prime minister rigged last year's polls. Sharif won the election by a landslide, taking 190 out of 342 seats in the national assembly.
The ballot was the first democratic transfer of power in Pakistan's history and also propelled Khan from a fringe player to head of the third-largest legislative bloc in the country.
Qadri wants Sharif to step down because he says the system is corrupt. He has promised free housing for the homeless, and welfare and subsidised food and electricity for the poor.