Militants in western Pakistan have bombed a bus carrying women students and then seized part of the hospital where survivors of the attack were taken, killing at least 21 people.

Over 27 people have been injured in the incident, according to officials.

The gunmen in Quetta, the capital of Baluchistan province, are reported to be still holed up in the emergency ward of a hospital, engulfed in a firefight pitting them against the security forces.

Security forces had forced their way into part of the Bolan Medical Complex, where dozens of patients and staff were believed to be trapped.

The attack in resource-rich Baluchistan is Pakistan's most lethal since the government of Prime Minister Nawaz Sharif took office last week and followed earlier explosions in a nearby town that killed a policeman and destroyed a historic building.

Quetta is a hotbed of sectarian violence, much of it targeting the Hazara ethnic minority, who are Shia Muslims.

The province is also racked by a separatist insurgency. It was not immediately clear who was responsible for the bus and hospital attacks, or whether they were aimed at the Hazaras.

City police chief Mir Zubair Mehmood said the students on the bus were from various ethnic groups.

The initial blast gutted the bus while it was on the campus of a local university for women, killing 11 students, and another explosion went off soon after at the hospital, the city's largest.

Those killed at the hospital included a senior government official, three security officials and a nurse, said Jan Mohammed Bulaidi, spokesman for Baluchistan's new chief minister.

The city's nursing federation said three more nurses and two family members of the student victims also died.