Twenty people were tortured and then murdered with clubs and knives at a Pakistani Sufi shrine, the police said on Sunday, in an attack purportedly carried out by the shrine's custodian and several accomplices.

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

The custodian of the shrine, Abdul Waheed, called on the worshippers to visit the shrine and then attacked them with his accomplices, said Liaqat Ali Chattha, deputy commissioner for the area.

"As they kept arriving, they were torturing and murdering them," Chattha told Geo TV.

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 told Reuters.

Police arrested Waheed. During his interrogation, the custodian told police he believed his victims were out to kill him, said Zulfiqar Hameed, Regional Police Officer for Sargodha.

"Waheed told police that he killed the people because they had tried to kill him by poisoning him in the past, and again they were there to kill him," Hameed told Reuters.

Reuters could not immediately find contact details for Waheed or any lawyer representing him.

With its ancient hypnotic rituals, Sufism is a mystical form of Islam that has been practised in Pakistan for centuries.

But in recent months, Sufi shrines have been targeted by extremist Sunni militants who consider them heretics, including a suicide bombing by Islamic State that killed more than 80 worshippers at a shrine in Lal Shahbaz Qalandar 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. Islamic State also claimed responsibility for that attack.