Pakistan's new parliament chose a prime minister from the main pro-government party today, rejecting the candidate of fundamentalist Islamic parties and ending a protracted struggle over the shape of a new ruling coalition more than five weeks after national elections.

Zafarullah Khan Jamali, a career politician and tribal leader from the province of Baluchistan, captured a narrow majority in the National Assembly with 172 of 328 votes. Fazlur Rahman, a Muslim cleric opposed to Pakistan's cooperation with the United States in the war on terrorism, ran a distant second with 86 votes.

The outcome came as a relief to the military government of President Pervez Musharraf, the army chief of staff who seized power three years ago in a coup d'etat. It signaled the emergence of a ruling coalition led by Jamali's party, the pro-government Quaid-e-Azam faction of the Pakistan Muslim League (PML-Q). It included independent lawmakers as well as defectors from the opposition Pakistan People's Party (PPP) led by former prime minister Benazir Bhutto.

The new coalition, analysts say, is unlikely to challenge Musharraf's alliance with Washington or his domestic policies, including gradual economic reform. They noted, however, that the coalition's slender majority means that the new government could prove unstable and prone to an early collapse.

Many Pakistanis remain deeply cynical about the elections as well as the horse-trading that followed, accusing Musharraf of manipulating the process to ensure a favorable outcome. Under constitutional amendments he imposed by fiat last summer, Musharraf will still retain ultimate power in Pakistan, including authority to dissolve parliament.

Musharraf defended his record in an hour-long speech Wednesday night, presenting himself, as he often does, as a modest military man who stepped in reluctantly to save the country from incompetent and venal civilian leaders. "The ship of the nation has been steered clear out of the stormy seas and is well set on its destination," he declared, promising to turn over executive authority to the new government within the next few days.

Jamali, the 58-year-old new prime minister, is a largely unknown figure outside Pakistan. He is a career politician from the Jamali tribe in Baluchistan, on the lawless frontier with Afghanistan, according to news reports and diplomats in the Pakistani capital, Islamabad.

He served three times as chief minister of Baluchistan, most recently in 1996, and was a deputy minister for rural development in the military government of Gen. Mohammed Zia ul-Haq, who died in a plane crash in 1988. He was elected to the National Assembly in 1977 and subsequently served as a minister for water and power. He is said to speak English extremely well and is a former field hockey player who has been active in promoting the sport in Pakistan.

The runner-up in the contest, Rahman, was the candidate of a six-party religious alliance known as the Muttahida Majlis-i-Amal, or MMA. In part because Musharraf had barred a number of potential challengers -- including Bhutto and former prime minister Nawaz Sharif -- from participating in the elections on corruption grounds, the religious parties did far better in the Oct. 10 contest than analysts had predicted, finishing third in the balloting behind the PML-Q and Bhutto's PPP.

In the negotiation that followed, the MMA emerged as a key power broker, courted as a possible coalition partner by both the PML-Q and PPP. The prospect of a coalition government including the religious alliance, perhaps with Rahman at its head, alarmed the United States and many secular-minded Pakistanis. Rahman was a strong supporter of the Taliban who backed the group well after the Sept. 11, 2001, attacks in the United States.

In the end, though, neither the pro-government PML-Q nor Bhutto's party could agree to the religious alliance's terms, and the PML-Q was forced to build its majority with small parties, independents and 10 defectors from the PPP. Such defections formerly were barred under Pakistan's constitution, but Musharraf recently changed the rules to allow them, adding to charges of unwarranted meddling.

"It is too sordid a way to get what he wanted," Mohammed Ziauddin, an editor of Dawn, a major English-language daily, said by telephone from the capital. "By keeping Benazir and Nawaz Sharif out, he allowed the religious element to take the balance of power, and after seeing that pattern emerge, he had no other alternative but to resort to this kind of manipulation."

While the religious parties will not be part of the ruling coalition, they will remain a major factor in Pakistani politics, controlling two of the four provincial assemblies and playing a prominent opposition role in parliament. In that capacity they are likely to influence legislation dealing with social issues, such as women's rights, and are sure to continue their criticism of Musharraf's ties to Washington.

"If the army does not listen, then the gap between it and civil society will widen," Rahman warned after today's vote. "Foreign policy should be reshaped on the basis of our sovereignty. We won't accept any interference and compromise on our sovereignty."

Zafarullah Khan Jamali, center, arrives at the National Assembly in Islamabad before his election as prime minister. Jamali was chosen over a Muslim cleric opposed to cooperation with the United States in the war on terrorism.