Mr. Masire attends a public event in London in 2012. (Justin Tallis/AFP via Getty Images)

Ketumile Masire, a cattle herder turned statesman who, as president of Botswana from 1980 to 1998, helped solidify his country’s standing as one of the most richly thriving nations in Africa, died June 22 at a hospital in the capital city of Gaborone. He was 91.

His death, announced in a statement by his family, was reported by the Associated Press. The cause was not disclosed.

Mr. Masire was widely heralded as a model leader in a model nation on a continent where poverty, corruption and violence had crushed many hopes for stability and prosperity.

“We have seen the promise of a new Africa whose roots are deep here in your soil, for you have been an inspiration to all who cherish freedom,” U.S. President Bill Clinton declared to Mr. Masire during a visit to Gaborone in 1998.

Clinton noted that in 1966 when Botswana — then known as Bechuanaland — obtained independence from Britain, it had two miles of paved roads and a single public high school. Its chief export was beef.

Ketumile Masire in 2000. (Antony Njuguna/Reuters)

The discovery of diamond reserves transformed the country’s prospects, and under Mr. Masire and his predecessor, Seretse Khama, the nation used its revenue to build roads and schools, to improve health care and expand access to clean water, to advance farming techniques and to extend life spans.

Khama, who had been the first president of independent Bot­swana, was featured in last year’s film “A United Kingdom,” starring David Oyelowo, with Rosamund Pike portraying the white Englishwoman Khama married in defiance of British authorities.

Mr. Masire — a self-described “farmer who has been drawn into politics” — was credited with leading his landlocked nation through a drought that dragged on for much of the 1980s. In 1989, he shared the Africa Prize for Leadership, valued at $100,000, from the charitable organization the Hunger Project in recognition of the food distribution efforts that helped the country avoid starvation during the crisis.

He navigated a delicate relationship with South Africa, Bot­swana’s neighbor to the south. While South Africa was Botswana’s major economic partner, Botswana opposed the apartheid system of racial segregation under which South Africans were ruled for decades before its dismantlement in the early 1990s.

“He had to walk a line [in] a really rough neighborhood,” said Chester Crocker, a Georgetown University professor and former assistant secretary of state for African affairs. “He had to get along with everybody, without sacrificing his principles.”

While many other African nations suffered under dictatorship, Botswana featured a robust democracy with little if any noticeable corruption. The “political inclusivity” Mr. Masire fostered, Crocker said, “is a magic formula, and it’s too rare in Africa and elsewhere.”

The stability of Botswana allowed its tourism industry to flourish in times of economic prosperity, with many visitors coming to witness its wildlife.

Ketumile Masire in 2001. (Alexander Joe/AFP via Getty Images)

Mr. Masire — often known as Quett — was born in Kanye, in southern Botswana near the South African border, on July 23, 1925. In his youth, he was a herder before enrolling in a primary school at 13, according to a statement from Botswana’s government announcing his death.

Crocker said Mr. Masire worked the land in a country that may go years without rain and learned a profound sense of self-reliance. He received a scholarship to attend a secondary school in South Africa that was said to have trained many leaders of the first government of independent Botswana.

After both of his parents died when he was in his early 20s, he suspended his education to become a teacher to support his siblings. He was a headmaster before saving enough money to purchase a tractor and pursue farming, distinguishing himself with modern agricultural techniques.

He also worked as a newspaper journalist, an activity that along with his community involvement helped draw him into politics. He served on tribal and regional councils and was a founder and secretary general of the Botswana Democratic Party, now the country’s dominant political party. According to the Encyclopedia of World Biography, he once traversed 3,000 miles of the Kalahari Desert to attend two dozen meetings over two weeks.

Before becoming president, Mr. Masire had served in roles including minister of finance and development planning and vice president.

After leaving office, he advised other African leaders and chaired an international panel that probed the Rwandan genocide of 1994. Crocker credited him with making important contributions to peace efforts in Congo and, more recently, Mozambique.

In his retirement, Mr. Masire established the Sir Ketumile Masire Foundation, a nongovernmental organization that seeks to improve agriculture, governance and children’s health in the region. He also tended the cattle on his ranch.

Mr. Masire’s wife, Gladys Olebile Molefi Masire, whom he married in 1958, died in 2013. They had six children. A complete list of survivors was not immediately available.

“We have a saying in Botswana: A man is never strong until he says what he believes and gives other men the chance to do the same,” Mr. Masire once told The Washington Post. “I am proud to say without a doubt . . . we are a strong democracy.”