At least 20 people have been tortured and then murdered with batons and knives at a Pakistani Sufi shrine, police say.

Four others were wounded during the attack on Sunday at the shrine on the edge of Sargodha, a remote town in the Punjab region.

Sargodha's deputy commissioner Liaqat Ali Chattha said the custodian, Abdul Waheed, and his four alleged accomplices had been arrested.

Mr Chatta said the custodian, who had confessed to the murders, was a retired government employee and seemed "mentally unstable".

He had called on worshippers to visit the shrine and then attacked them with his accomplices, Mr Chattha told Pakistan's Geo TV.

"As they kept arriving, they were torturing and murdering them," he said.

Mr Chatta said the custodian was allegedly in the practice of beating and torturing devotees to "cleanse" them.

Regional police officer for Sargodha, Zulfiqar Hameed, said the custodian told police he believed his victims were out to kill him.

Pervaiz Haider, a doctor in a Sargodha hospital, said most of the dead were hit on the back of the neck.

"There are bruises and wounds inflicted by a club and dagger on the bodies of victims," he said.

Sufism is a mystical form of Islam that has been practised in Pakistan for centuries

In recent months, Sufi shrines have been targeted by extremist Sunni militants who consider them heretics, including a suicide bombing by the so-called Islamic State group that killed more than 80 people at a shrine in southern Sindh province.

Last November, an explosion ripped through another Sufi shrine, the Shah Noorani in southwestern Pakistan, killing at least 52 people.

IS also claimed responsibility for that attack.

Reuters/AP