JOHANNESBURG — Two white South African farmers were sentenced to a combined 41 years in prison on Wednesday for killing a black teenager whom they had accused of stealing sunflowers, bringing to a close a case that had inflamed tensions in a rural town and exposed the nation’s enduring racial divisions.
During a hearing at the High Court in Mahikeng that was packed with black and white South Africans, Judge Ronald Hendricks described the actions of the farmers, who were convicted of throwing the 15-year-old boy off a moving truck in April 2017, as “disgraceful” and “appalling.”
The boy, Matlhomola Mosweu, 15 died after breaking his neck. His death set off riots in the town of Coligny, about 125 miles west of Johannesburg.
The two farmers — Pieter Doorewaard, 28, and Phillip Schutte, 35 — were found guilty of murder, kidnapping and other charges. Mr. Doorewaard was sentenced to 18 years in prison, and Mr. Schutte to 23 years.
They had claimed that after they caught Mr. Mosweu stealing, they put him on the truck to take him to a police station. But the teenager, they said, then jumped off the vehicle.
The judge ruled that the killing had not been planned or premeditated, but had “happened on the spur of the moment.” He added, “The community of Coligny was terrorized by this.”
The killing prompted days of rioting and looting in the farming town, especially against white-owned businesses.
As in all of South Africa, one of the world’s most unequal societies, racial tensions had simmered just below the surface in Coligny, where farms and other businesses are still largely owned by whites and other individuals who are not black South Africans.
Most black residents, who depend on white-owned farms for work, live in a nearby township. Mr. Mosweu had lived in a shantytown for newer arrivals, called Scotland informal settlement.
The courtroom was filled with members of the Economic Freedom Fighters, an opposition party that has long pushed for the expropriation of white-owned land without compensation. Pressure from the party, a spinoff of the governing African National Congress, has compelled the A.N.C. to adopt a similar position under President Cyril Ramaphosa.
Tensions between white farmers and black residents have grown across the country since the A.N.C. adopted the policy in December 2017. Mr. Ramaphosa has tried to assuage fears in and outside South Africa that the policy would not lead to violence or economic turmoil, but most investors are taking a wait-and-see attitude before national elections in May.
Lobby groups for white farmers have accused the South African authorities of covering up what they say is the widespread, racially motivated killings of white farmers.
While there is no evidence to support their claims, some have visited the United States to win support for their cause. Right-wing groups and news outlets in the United States have fanned reports that such killings, and even genocide, are being perpetrated against white South Africans.
Last August, President Trump, apparently reacting to a report on Fox News, said on Twitter that he was directing his secretary of state to look into what he described as the targeting of white farmers for land grabs and “large-scale killing” in South Africa.