COLOMBO, Sri Lanka — A majority of Sri Lankan lawmakers voted Wednesday morning to remove Mahinda Rajapaksa as prime minister, saying that his appointment last month was illegal.

Mr. Rajapaksa is considered the strongman of Sri Lankan politics, a wealthy, powerful former president who has been accused of grave human rights abuses. The country has been tied in knots since late last month when President Maithripala Sirisena abruptly fired the previous prime minister, Ranil Wickremesinghe, and appointed Mr. Rajapaksa to the post.

It was a rambunctious, unruly few hours in Parliament this morning.

Lawmakers allied with Mr. Wickremesinghe walked into the chamber wearing black sashes that read “For democracy.’’ The gallery was packed with journalists, diplomats and everyday citizens. Lawmakers allied with Mr. Rajapaksa did whatever they could to block a vote of no confidence. Some yelled, while others tried to grab the ceremonial mace, the parliamentary symbol of power. Some even called the speaker of Parliament a “mad fool.”

But a majority of lawmakers were determined to hold the vote. Mr. Rajapaksa then walked out. When the ayes were counted, 122 out of 225 said they wanted Mr. Rajapaksa gone.