HYDERABAD, India — Nepal’s chief judge was sworn in as head of an interim government on Thursday morning in an effort by the country’s squabbling political parties to hold new elections.

Chief Justice Khil Raj Regmi of Nepal’s Supreme Court was sworn in by President Ram Baran Yadav at around 9 a.m., according to Mr. Yadav’s spokesman. A home minister and law minister were sworn in at the same time.

“People are very optimistic today all over the country that at least now this government will be able to hold elections and the country will move forward,” said the spokesman, Rajendra Dahal.

An agreement among the country’s four largest political parties was signed late Wednesday night after months of bickering. But the agreement was opposed by many smaller parties as well as some legal groups, and there were widespread protests.