The blast took place at a gathering of the conservative Jamiat Ulema Islam-Fazl (JUI-F) party, known for its links to hardline political Islam, in the former tribal area of Bajaur, which borders Afghanistan.
An emergency has been declared in the hospitals of Bajaur and adjoining areas where most of the injured were taken, said district police officer Nazir Khan. The critically injured were transported from Bajaur to hospitals in the provincial capital Peshawar by military helicopters.
A statement from Rescue 1122, a first-responder service, put the death toll at 42.
Khan said the explosion, at a JUI-F workers convention in Khar town of Bajaur, had left more than 130 injured, many seriously.
The provincial police chief Akhtar Hayat told Reuters the explosion was caused by a suicide bomb.
Pakistan has seen a resurgence of attacks by Islamist militants since last year when a ceasefire between the Tehreek-e-Taliban Pakistan (TTP) and Islamabad broke down. A mosque bombing in Peshawar killed over 100 people earlier this year.
While the TTP and its associated groups have been behind a majority of attacks in Pakistan in recent months, the group distanced itself from Sunday's attack, which its spokesman condemned.
The TTP pledges allegiance to, but is not directly a part of, the Taliban in western neighbour Afghanistan. Pakistan's security forces say the TTP have sanctuaries in Afghanistan, which the Taliban run-administration there denies.
Afghanistan's administration condemned the explosion in a statement by their spokesman Zabihullah Mujahid.
The TTP are not the only militant group to carry out attacks in the area, which has also been hit by a local chapter of the Islamic State.
The targeted party, the JUI-F, is a major ally of the coalition government of Prime Minister Shehbaz Sharif, which is preparing for national elections to be held by November.
Sharif condemn the blast, calling it an attack on the democratic process of Pakistan. He vowed that those responsible would be punished.
The U.S. Embassy in Islamabad and former Pakistan Prime Minister Imran Khan also condemned the explosion in posts on messaging platform on X, formerly known as Twitter.