Pakistani lawmakers on Tuesday elected a textile magnate to be the next president of a country plagued by Islamist extremism, only hours after Taliban militants launched a prison break freeing hundreds of inmates.

The attack highlighted one of the major challenges that Mamnoon Hussain will face once he takes over the largely ceremonial post of president. Security forces appeared totally unprepared for the raid in the northwest, despite senior prison officials having received intelligence indicating that an attack was likely.

Pakistan’s president is not elected by popular vote but by lawmakers in the Senate, the National Assembly and the assemblies of the country’s four provinces. Many had predicted Tuesday’s outcome because the ruling Pakistan Muslim League-N party, which nominated Hussain, won majorities in the National Assembly and the assembly of the country’s most populous province, Punjab, last month.

Hussain received 432 votes, according to Pakistan’s election commission. The only other candidate, retired judge Wajihuddin Ahmed, received 77 votes.

Prime Minister Nawaz Sharif will remain the most powerful figure in the civilian government in Pakistan, which is a key ally of the United States in battling Islamist militants and negotiating an end to the war in neighboring Afghanistan.

Hussain was born to an industrialist family in 1940 in the Indian city of Agra. His family settled in Karachi, the capital of Pakistan’s Sindh province, after the country was carved out of British India in 1947 and set up a textile business there.

He is a longtime member of the PML-N and served as governor of Sindh for about four months in 1999 but otherwise has not been a prominent figure in national politics.

Hussain will replace Asif Ali Zardari, whose five-year term ends Sept. 8.

The prison attack Monday night occurred in the town of Dera Ismail Khan, near Pakistan’s semiautonomous tribal region, the main sanctuary of Taliban and al-Qaeda militants.

The militants killed six police officers, six Shiite Muslim prisoners and two civilians, said Dera Ismail Khan’s commissioner, Mushtaq Jadoon. One of the Shiites was beheaded. Many hard-line Pakistani militants consider the country’s minority Shiites heretics.

A Taliban spokesman later asserted responsibility for the attack and said about 300 prisoners escaped. Jadoon said 253 prisoners, including 25 “dangerous terrorists,” were freed.

Khalid Abbas, a police officer who heads the prison department in Khyber Pakhtunkhwa province, said officials recently received intelligence indicating the likelihood of an attack but didn’t expect it so soon.

— Associated Press