An attack on a university in Pakistan which left at least 20 people dead has been ended by security forces.

The attackers triggered a heavy gun battle with police and army troops in a town near Peshawar, but officials said the operation to clear the site had now finished, and that four gunmen were killed.

The attack began shortly after Bacha Khan University opened for classes in the town of Charsadda, 20 miles outside Peshawar, said deputy commissioner Tahir Zafar.

The Pakistani Taliban claimed responsibility for the brazen assault which harked back to a December 2014 attack on a school in Peshawar that killed more than 150 people, mostly children.

The attackers traded gunfire with troops and several explosions were heard from the area.

A Taliban leader, Khalifa Umar Mansoor, said in a phone call that a four-man team conducted the assault in revenge for scores of militants killed by Pakistani security forces in recent months.

Mansoor was the mastermind of the Peshawar school attack.

The main spokesman for the Pakistani Taliban, Mohammad Khurasani, reiterated the claim of responsibility.

Mr Zafar said a chemistry professor and a student were among those killed. Television footage showed heavy military presence at the university, troops rushing in and people fleeing. Ambulances were at the scene and the wounded were being taken to hospital.

Prime minister Nawaz Sharif was quoted on the website of the Daily Pakistan as saying: "We are determined and resolved in our commitment to wipe out the menace of terrorism from our homeland."

Bacha Khan University is named after the founder of a liberal, anti-Taliban political party. The Pakistani Taliban has in the past targeted the party for its anti-militant policies.

Pakistan's north west and its lawless tribal area bordering Afghanistan is a highly volatile region. Pakistani forces have been carrying out a major operation against the Taliban and other militants there since 2014.

Last month, as the country marked the first anniversary of the Peshawar school attack, the military claimed "phenomenal successes" in the war and said it had killed around 3,500 insurgents since launching the operation.

The school attack, which was claimed by the Pakistani Taliban, horrified the country and led the government to lift a 2008 moratorium on the death penalty. Pakistan hanged four militants last month who were sentenced to death over the attack.

Video: Reuters

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.