KATHMANDU, Nepal — Lawmakers in Nepal on Tuesday elected a veteran politician as the country’s 10th prime minister in 11 years.

Parliament selected Sher Bahadur Deuba as prime minister, and it will be the fourth time he has held that post. Mr. Deuba is likely to be in power for only a few months because parliamentary elections are to be held by January 2018.

The speaker of Parliament, Onsari Gharti Magar, announced that Mr. Deuba, the leader of the country’s largest political party, Nepali Congress, had received 388 votes, more than the required majority. A total of 170 lawmakers voted against him.

He will lead a coalition government with the Communist Party of Nepal (Maoist-Center), whose leader, Pushpa Kamal Dahal, was previously prime minister. Mr. Dahal resigned last month, honoring an earlier deal to allow Mr. Deuba to assume the post.

The coalition is also supported by smaller parties that are expected to be part of the new government.

“I am committed to hold all three levels of elections,” Mr. Deuba said, referring to local, provincial and parliamentary polls.

A second phase of local elections to choose municipal and village council officials is scheduled for June 28.

One of Mr. Deuba’s major challenges will be conducting provincial elections in seven newly formed states opposed by ethnic groups in southern Nepal.

A new Constitution adopted in 2015 carved Nepal into seven states, but months of protests against the plan by the Madhesi ethnic group left more than 50 people dead and blocked the border with India, resulting in severe shortages of fuel, medicine and other supplies.

Mr. Deuba will need to negotiate with these ethnic groups, which are threatening to protest against the elections unless their demand for more territory in their states is granted.

Mr. Deuba also has the tricky task of balancing the country’s ties with Nepal’s giant neighbors, India and China. A landlocked country, Nepal is bordered by India on three sides and China on one.

Most oil products and supplies are imported from India, and China provides financial aid and investment.

“I want to assure both China and India that we will not let our territory be used against either nation,” Mr. Deuba said.

China worries about anti-China protests by exiled Tibetans in Nepal, and India is concerned about the possibility of militants entering India through its open border with Nepal.

Mr. Deuba first became the prime minister in 1995 and governed for two years. His second term was cut short when the king at the time, Gyanendra, dismissed him, calling him incompetent. During Mr. Deuba’s third turn as prime minister, King Gyanendra seized absolute power and removed him.