The military has denied playing a role.

Mr. Sharif denounced the Supreme Court ruling but stopped short of criticizing the military. Without offering any details, he said his removal was the result of a conspiracy.

In recent interviews, Mr. Sharif maintained that he was not guilty of corruption. His failure to disclose his role in a Dubai-based company run by one of his two sons led the court to cite a clause of the Constitution that requires public office holders to be “honest and faithful.”

On Wednesday, it took Mr. Sharif’s convoy, consisting of at least 500 vehicles, six hours to reach neighboring Rawalpindi by evening because of the crowds, though the turnout in Rawalpindi was smaller than party leaders had expected.

After midnight, Mr. Sharif spoke from behind bulletproof glass and lashed out at the court’s ruling. “It is an insult to your vote,” he said, referring to his ouster, as the crowd in front roared. But he told his supporters, “I am going to my home and do not want you to get me restored.”

Opponents criticized his rally, saying it showed contempt for the court’s ruling.

“We cannot ignore the fact that Nawaz’s party is still in power and such rallies are nothing but an effort to influence the accountability process by using political pressure,” said Fawad Chaudhry, a senior spokesman of the political party Pakistan Tehreek-e-Insaf.

Mr. Sharif chose to go to Lahore by the Grand Trunk Road, which connects several cities of Punjab Province. His party has a strong hold over almost all cities along that highway, and he was hoping for a large turnout that would help him reclaim his position as a populist leader.

Lahore is the capital of Punjab, the most populous and politically significant province. Mr. Sharif and his younger brother Shehbaz Sharif have held sway there for decades. Party workers there made elaborate arrangements for the former prime minister’s arrival. Main thoroughfares of the city were festooned with banners and posters welcoming him home.