The blast targeted the Jamiat Ulema-e-Islam-F (JUI-F) party, a government coalition partner led by an influential firebrand cleric.
More than 400 party members and supporters had gathered under a canopy when the attack took place in the town of Khar, near the border with Afghanistan.
"As we awaited the arrival of the central leadership, a sudden and loud bang echoed through the venue," said Sabeeh Ullah, a 24-year-old supporter who fractured his arm in the blast.
"I found myself lying next to someone who had lost their limbs. The air was filled with the smell of human flesh," he said.
Riaz Anwar, the health minister for Khyber Pakhtunkhwa province, said local hospitals reported 39 dead and 123 wounded, including 17 patients in serious condition.
"It was a suicide attack, with the bomber detonating himself in close proximity to the stage," he said.
Provincial governor Haji Ghulam Ali confirmed the toll.
Images from the blast site circulating on social media showed bodies strewn around the scene, and volunteers helping blood-soaked victims to ambulances.
Pakistan's national assembly is due to dissolve in the next few weeks ahead of elections expected in October or November, and political parties are already preparing to campaign.
The blast coincides with a visit by a senior delegation of Chinese officials, including Vice Premier He Lifeng, who are due to arrive in the capital later Sunday evening.