JOHANNESBURG — Voters in Botswana re-elected a president who had received international attention for lifting a ban on hunting elephants and overseeing the decriminalization of homosexuality.

President Mokgweetsi Masisi’s party was proclaimed the winner by the country’s chief justice on Friday after a fiercely contested election. Botswana, a diamond-rich country of just over two million people, has long been held up as one of Africa’s most stable democracies.

The election, held on Wednesday, was electrified by a clash between Mr. Masisi and his predecessor as president, Ian Khama, who broke with the party that has governed the country since independence.

While votes were still being counted, the chief justice, Terrence Rannoane, said in a televised address that the partial results were sufficient to secure a parliamentary majority for Mr. Masisi’s Botswana Democratic Party.