Gunmen on motorcycles have shot and killed seven Pakistani police officers involved in a polio vaccination campaign in two separate attacks in the port city of Karachi.

The officers killed had been deployed to protect health workers administering the vaccinations. No health staff were harmed in the attacks, which occurred minutes apart, and police said authorities have no plans to suspend the polio campaign as a result.

A breakaway faction of the Pakistani Taliban that calls itself Jamat-ul-Ahrar has claimed responsibility for the attack.

In an email, the group's spokesman Ahsanullah Ahsan said it was part of its campaign against security forces.

However, Islamic militants have in the past targeted vaccination efforts both in Pakistan and in neighbouring Afghanistan based on conspiracy theories that they are a cover for a Western-led sterilisation campaign.

The Pakistani military has launched multiple offensives against militant hideouts in the tribal regions and elsewhere, but the insurgents have proven resilient.

Pakistani prime minister Nawaz Sharif strongly condemned the "terrorist attack", and said the officers had sacrificed their lives to secure the future of the nation's next generation. Polio, which can cause paralysis and death, remains endemic in Pakistan.

Also on Wednesday, the Pakistani army said troops had freed 24 police officers captured by a criminal gang earlier this month in the eastern Punjab province.

Army spokesman Lt Gen Asim Saleem Bajwa said the gang leader and his men surrendered during the police operation in Rajanpur district. The development came days after a notorious criminal gang, the Chutto, killed six policemen when police raided its hideout.