LONDON -- The troubling gap between politics and governance in Pakistan came into stark relief on Tuesday, when lawmakers elected the country's 12th president just hours after Taliban militants shot their way into a major jail, freeing about 250 prisoners.
As predicted, Mamnoon Hussain, a little-known textiles magnate from Karachi and a loyalist of Prime Minister Nawaz Sharif, won the presidential vote in the national and provincial legislatures. He will take over from President Asif Ali Zardari, a contentious figure who is due to step down on Sept. 8.
The election was another important democratic step in a country that has seen four military coups since the 1950s, the most recent in 1999. It confirmed Mr. Sharif, whose party emerged victorious from May's general election, as the most powerful civilian leader.
But away from the democratic process lay sobering reminders that Taliban insurgents, not power-hungry generals, now present the most pressing challenge to state authority in Pakistan.
In the northwest, heavily armed militants mounted an audacious jailbreak just before midnight on Monday at a century-old prison at Dera Ismail Khan. The site is just outside the tribal belt, where the majority of C.I.A. drone strikes have taken place.
Up to 150 fighters, armed with guns and grenade launchers, blew holes in the perimeter wall, the police said. Some fighters were disguised as policemen, while others wore suicide-bomb vests.
As they stormed the building, breaking open cells, the attackers used a megaphone to call out names of specific prisoners and cried, "God is great" and "Long live the Taliban," security officials said.
The provincial authorities said the escaped prisoners included 25 militants with the Taliban and Lashkar-e-Jhangvi, a sectarian militant group that has killed hundreds of minority Shiites this year.
At least 14 people died in the assault, including 6 Shiite prisoners, several of whom were beheaded. The police said a squad of foreign militants, some from Uzbekistan, had helped secure a road to ensure that the militants could escape back to South Waziristan in the tribal belt.
The assault followed a week of countrywide bloodshed that underscored the state's crumbling ability to fight militant violence. Baluch nationalists attacked a coast guard post on the Arabian Sea in Baluchistan Province, killing seven people.
In Sukkar, in neighboring Sindh Province, Taliban militants attacked a regional office of the Inter-Services Intelligence spy agency, resulting in at least nine deaths. A double suicide bombing in the tribal belt, targeting Shiites, killed 57 people and wounded more than 150.
And in Baluchistan on Tuesday, militants shot a police officer who had been guarding health workers administering polio vaccination drips to children in Pishin, a Taliban refuge near the Afghan border.
Analysts said the spate of violence highlighted the failure of the country's civilian and military leaders to deliver on promises of a coordinated counterterrorism strategy.
"Every day it seems the state is losing more and more control," said Ahmed Rashid, an analyst and author of several books on the Taliban. "The attacks are occurring across the country, and becoming more pernicious. The militants can see that the government doesn't have a national security plan."
Mr. Rashid said there seemed to be "a lot of dithering and debate" between the army, led by Gen. Ashfaq Parvez Kayani, and the government, led by Mr. Sharif. "And we still don't have a plan," he said.
Some blame for the Taliban jailbreak fell on the former cricketer Imran Khan, whose party has led Khyber-Pakhtunkhwa Province, where Dera Ismail Khan is, since the election in May.
Mr. Khan favors talking to the Taliban instead of fighting them, and has frequently attributed the chaos in the region to the presence of American troops in Afghanistan and C.I.A. drone strikes in the tribal belt.
His provincial government faced fresh criticism on Tuesday after it emerged that the intelligence services had warned of the jailbreak just three days earlier. In a letter marked "secret," which The New York Times has seen, intelligence officials warned that militants led by Umer Khitab had obtained a map of the jail and were preparing an assault similar to a jailbreak in Bannu in April 2012.
Speaking outside Parliament on Tuesday, Mr. Khan blamed administrative failures of officials of the previous government for the lapses, saying they "had allowed themselves to be part of America's war."
Political wrangling over Pakistan's relationship with America formed part of the general criticism of Mr. Zardari, the departing president, who otherwise spent much of his five-year term in rolling battles with judicial and military leaders, all the while struggling to shake off longstanding corruption accusations.
Mr. Zardari's political authority stemmed largely from his status as the widower of Benazir Bhutto, the former prime minister, who was assassinated in 2007. He confounded his many critics, who regularly predicted his political demise, through adroit maneuvering. He survived intense pressure from the Supreme Court, led by Chief Justice Iftikhar Muhammad Chaudhry.
And he initiated constitutional changes that drained the presidency of power in a bid to make it more difficult for the military to meddle directly in politics.
If Mr. Zardari owed much of his power to his high-profile marriage, Mr. Hussain's main qualification seems to be his low profile.
Born in India in 1940, Mr. Hussain served briefly as the governor of Sindh Province in 1999, when Gen. Pervez Musharraf toppled Mr. Sharif's previous government in a bloodless coup. Mr. Hussain remained a steadfast ally of Mr. Sharif in those days, defying military pressure and intimidation.
But his ventures into electoral politics were less successful; he failed to win a parliamentary seat in 2002 and since then had concentrated largely on his textile business.
Political analysts say the presidency may be his reward for his unflinching loyalty to the Sharif family. Before his victory on Tuesday, he promised to use the office to restore peace in Karachi, his native city, which is splintered by ethnic political violence.
Ismail Khan contributed reporting from Peshawar, Pakistan, and Salman Masood from Islamabad, Pakistan.
Correction: July 31, 2013, Wednesday
This article has been revised to reflect the following correction: An earlier version of this article misidentified a sectarian militant group that has killed hundreds of minority Shiites this year. It is Lashkar-e-Jhangvi, not Lashkar-e-Taiba.
This article originally appeared in The New York Times.