The blast was the deadliest attack in the region since May 11 national and regional elections installed a new government in the northwestern province of Khyber Pakhtunkhwa.
The carnage poses a challenge for cricketer-turned-politician Imran Khan, whose party won the provincial election there on a platform of negotiating with the Pakistani Taliban to bring an end to the years of fighting and attacks there.
The bombing in the village of Sher Garh near the city of Mardan killed 29 people and wounded at least 57, said a senior police officer in Mardan, Tahir Ayub Khan.
Pakistani TV channels showed footage of the bombing scene, splashed with blood and scattered body parts, as many of the survivors, their clothes soaked with blood, scrambled to get away. Local residents comforted the families of the victims as they cried out in anguish and beat their chests.
"Are you Muslim?" screamed an eyewitness, Nisar Khan, addressing the attackers. "Are you animals? Are you beasts?"
Many of the wounded were taken to hospitals in the provincial capital of Peshawar, about 65 kilometers (40 miles) away.
Speaking as doctors were examining him, Azeem Khan said a local cleric was leading the funeral prayers when he heard a deafening explosion and was knocked to the ground.
"People were running away for safety," he said. "Mourners at the funeral were crying for help after the blast."
Another eyewitness told Pakistan's Dunya television that 700 to 800 people were attending the funeral when the suicide bomber detonated the device.
The lawmaker, Imran Khan Mohmand, ran in Pakistan's May 11 elections as an independent candidate and later supported the party of Imran Khan, the ex-cricketer. He was the second provincial lawmaker affiliated with the party to be killed since the election. The other lawmaker, also an independent who later joined Khan's party, was shot dead earlier this month.
The Pakistani military has been fighting to root out Pakistani Taliban and affiliated militants from the tribal areas, a region that borders Afghanistan. The militants have vowed to overthrow the government and have carried out a campaign of bombings and shootings, mostly in the northwest, that have killed tens of thousands of civilians and security forces in recent years.
Khan campaigned on an anti-American platform in which he blamed the CIA's drone program and the war in Afghanistan for leading to much of the violence in Pakistan. He also favored negotiations with the Pakistani Taliban instead of military operations against them, and many of his aides and supporters said the party would not allow Pakistan to be used to ferry supplies to and from NATO troops in Afghanistan.
During the campaign, the Pakistani Taliban largely refrained from attacking members of Khan's Pakistan Tehreek-e-Insaf Party as well as the Pakistan Muslim League-N, which won the election. The militant group focused most of its attacks on three other parties, including the Pakistan People's Party, then in power, which supported military operations against the Pakistani Taliban in the northwest.
As a result, PTI and PML-N were able to campaign relatively freely, holding large rallies across the country, including in the volatile northwest.
Khan's party came in third in the parliamentary elections but won enough seats to form the provincial government in Khyber Pakhtunkhwa, putting him and his party in charge of a crucial region in the struggle against militants.
Imran Khan insists that the only way to end the crisis in the northwest is through negotiations, though critics say the militants in the past have used talks as a way to consolidate their strength, and then they go back to fighting.
Even after the bombing Tuesday, a senior party leader said it would push ahead with its goal of peace talks.
"Our policy is clear, we have been saying that we will hold a peace dialogue," said Shaukat Yousufzai, the minister of information in Khyber Pakhtunkhwa. "As long we don't bring all the stakeholders to the negotiating table, we can't get rid of ... terrorism."
The violence is a major test for Prime Minister Nawaz Sharif, who was elected on a platform of ending crippling electricity blackouts and fixing the country's economy. He supports of talks with the Pakistani Taliban to end the violence.
The prime minister's office released a statement condemning the bombing at the funeral.
Associated Press writer Asif Shahzad in Islamabad contributed to this report.