The attack occurred in a government high school in Mingora town while funeral prayers were being held for Javed Iqbal, a senior police officer who was killed in a roadside bombing earlier in the day, said Deputy Inspector General of Police Syed Akhtar Ali Shah.
He told The Associated Press by telephone that the attack was carried out by a suicide bomber and that the injured had been moved to a hospital.
Mingora, in Swat Valley in northwestern Pakistan, is 105 miles from Peshawar, a town at the border with Afghanistan.
President Pervez Musharraf sent thousands of troops to the scenic Swat Valley earlier this year to quell an uprising led by a pro-Taliban cleric. The army claims it has dispersed thousands of his militant followers, but attacks persist. Last week, a roadside bomb hit a wedding party, killing 12 people.
On Friday morning, Iqbal, the deputy police chief of Lakki Marwat district, and his driver were killed by a roadside bomb while they were driving through the district. It was night by the time his body was brought to his hometown of Mingora for his funeral.
"Because it was dark, the suicide bomber was able to mingle among the people easily," said Shahbuddin, an assistant inspector of police who was at the funeral on security duty.
He told the AP that the explosion occurred just as the pall bearers lifted the coffin to carry it toward the grave.
About 800 people were at the funeral, including civilians and police officials, said Shahbuddin, who uses one name.
"As the coffin was lifted I moved toward the gate but suddenly a big explosion took place, which dashed me against the gate. ... It was hell. Everybody was crying for help," said Shahbuddin, who was slightly injured.
He said he later went to the hospital where the injured were taken.
"I have seen 35 dead and over 60 injured in the hospital and am now completing the paperwork," he said.
Dr. Fazal Wahab, who was treating the injured, said the hospital was overwhelmed by the high casualties.
"We have treated a large number of injured, some in very critical condition," he told the AP.
Among the dead was Iqbal's son, Ghazan, the ARY OneWorld private television network reported. It put the death toll at 37 but this could not be confirmed.
District chief Arshad Majeed, who was at the hospital, said authorities were making an emergency appeal for blood donations. He could not immediately give a tally of the dead and wounded.
"We need blood for the injured people," he said, before hanging up.
Taliban militants have stepped up attacks and taken control of tracts of northwestern Pakistan bordering Afghanistan in the past several years.
Before militants took root last summer, Swat attracted tourists because of its fine mountain scenery.