NAIROBI, Kenya — John Magufuli, a surprise candidate, trained chemist and government minister appreciated for his corruption-busting tactic of hiding in trucks and popping out at weigh stations to nail crooked police officers, handily won Tanzania’s presidential election, the National Electoral Commission announced on Thursday.

Mr. Magufuli, who turned 56 on Thursday, trounced his closest rival, Edward Lowassa, a former prime minister and opposition leader, getting 58 percent of the vote to his 40 percent. Mr. Magufuli’s victory extends the rule of the Party of the Revolution, also known as Chama Cha Mapinduzi, or C.C.M., the once-socialist political party that has dominated Tanzania, under one name or another, since independence in the 1960s.

“This election is sending signals that it is almost impossible to dislodge C.C.M. from power,” said Kitila Mkumbo, an education professor at the University of Dar es Salaam. “It is so much connected to the government, very much connected to people’s lives. It’s present everywhere.”

Mr. Lowassa has not conceded defeat, refusing to sign papers closing off the election and filing a petition with the election commission demanding a recount. He complained bitterly this week that the governing party had rigged the election, held Sunday, though he and other opposition leaders failed to provide much evidence.