IS gained its first toe-hold in the country in January 2015 when six Pakistani Taliban leaders switched their allegiance over from Al-Qaeda

Rawalpindi: Pakistan's military on Thursday admitted for the first time that the Islamic State group had a presence in the country but said it had apprehended hundreds of its militants and prevented them from carrying out major attacks.

The army's spokesman Lieutenant General Asim Bajwa said forces had foiled planned attacks by IS on foreign embassies and Islamabad airport, but denied the group was behind last month's suicide blast on a hospital that killed 73, as it had claimed.

IS gained its first toe-hold in the country in January 2015 when six Pakistani Taliban leaders switched their allegiance over from Al-Qaeda, but has since struggled for traction in the face of competition from well-established groups.

Pakistan has been battling an Islamist insurgency since shortly after it decided to ally with the US following its invasion of Afghanistan in 2001. In 2007, Pakistani jihadists formed their own Taliban faction that has deep ties to Al-Qaeda, IS's main rival.

"Daesh tried to make an ingress into Pakistan, but the core of its group have now been apprehended," army spokesman Lieutenant General Asim Bajwa told a press conference, using the group's Arabic acronym.

Bajwa added that a total of 309 militants — from both its planning wing (Kutaiba Haris) and fighter wing (Kutaiba Mubashir), including its "mastermind" Hafiz Umar and top commander Ali Rehman had been held and the group had been contained.

The group's leader in Pakistan and Afghanistan was killed in a US drone strike in Afghanistan last month.

The spokesman said IS had carried out several small-scale attacks including the killing of human rights activist Sabeen Mahmud in Karachi in 2015, clashed with and killed security personal, as well as committing several grenade attacks on TV channels that had injured journalists.

But he denied it had been behind an attack on a hospital in the southwestern city of Quetta last month that killed 73 people, including most of the city's senior lawyers, in the second deadliest attack of the year. The suicide bombing was also claimed by Taliban faction Jamaat-ul-Ahrar.

"We haven't gotten any evidence of any linkage with Daesh — (the claim) was an attempt to glorify themselves".

An attack on a bus in Karachi in May, 2015 that killed 46 people was the first major incident officially claimed by IS in Pakistan, but Bajwa stated that one of the militants involved had pledged fealty to the group only when in custody.

Analysts have previously said the group's de-centralised command structure encourages elements not in communication with its leaders to carry out attacks and then pledge their allegiance.