The man was being held for allegedly burning a copy of the Koran in public. The incident took place on the outskirts of Bahawalpur, in Punjab province.
Witnesses said hundreds of people looked on as he screamed for help.
The area where the lynching took place is home to hundreds of madrassas - religious schools - run by radical Islamist or sectarian groups.
Police said they detained the man after locals complained that he had desecrated the Koran.
But before the allegation could be investigated, thousands of angry people surrounded the police station, police said.
"They were demanding that we kill him in front of them, or they'll take him away and kill him themselves," police inspector Ghulam Mohiuddin told the BBC.
After officers unsuccessfully tried to calm the crowd, it attacked the station, as police tried to disperse it with tear gas. Several policemen were wounded in the violence.
The mob put up roadblocks to prevent police reinforcements from reaching the area, officers said.
"We were totally outnumbered. There were too many of them and they were hysterical. Eventually, they succeeded in taking him away," said one.
- Salva Kiir sacks top South Sudan officials
- Lawyer wants Chinedu to appear in court
- Maji marefu’s futile effort to find stolen property
- Can chickens really be cleverer than a toddler? Studies suggest animals can master numeracy and basic engineering
- Freedom of media under threat in Eastern Africa
- Rapid desertification in Kenya threatening livelihood