The year is 1981, and South Africa’s apartheid government is embroiled in a vicious war along the southern Angolan border. Like all white boys over the age of 16, Nicholas Van der Swart is conscripted for two years of mandatory military service—a brutal period of indoctrination as the white minority government seeks to protect its borders from the threat of communism and “die swart gevaar” (“the black danger”).

For Nicholas (Kai Luke Brummer), that service grows increasingly fraught when he finds himself attracted to a fellow conscript. In a world where the word “moffie” — an Afrikaans slur for “gay” — is used to berate anyone who doesn’t live up to a perceived masculine ideal, Nicholas has to come to terms with his desires while also surviving a war being fought on behalf of a government whose racist policies had already made it a pariah state around the world.

“Moffie” is the fourth feature by Oliver Hermanus, the critically acclaimed director of Cannes Un Certain Regard player “Skoonheid” (Beauty) and “The Endless River,” which was the first South African film selected for the official competition at the Venice Film Festival. Based on the novel by André-Carl van der Merwe, it’s a riveting exploration of South African masculinity and the social, political and cultural forces that shaped it during apartheid rule. The film has its world premiere Sept. 4 in the Horizons section in Venice.

“Moffie” examines a little-known chapter in South African history, set just before internal pressure and international condemnation began to bring about the end of the apartheid regime. “This army and this conflict disappeared just around the time that [Nelson] Mandela came out of jail, and the road to democracy was being paved,” said Hermanus. Though compulsory military service left a profound psychological mark on a generation of white South African men, “there was no space for the trauma of white men at this time, when black people were being liberated.”

That trauma has a complicated legacy in South Africa, where questions of race-based economic inequality remain relevant 25 years since the end of apartheid. Hermanus himself has wondered if a story about white pain deserves to be told. But the director noted that “Moffie” is especially relevant in the context of the #MeToo movement.

“If we want to talk about white men today, or men in general, in the climate that we live in, maybe it is important to look at how these men … have been made for the last century in South Africa,” said Hermanus.

Nearly four decades since the end of the so-called Border War, many of the conscripts depicted in “Moffie” have themselves gone on to be fathers. The stories of what they endured during the war have largely remained untold; many of the actors in the film, said Hermanus, recalled hearing about that period in their fathers’ lives for the first time.

Many also came to question whether the toxic masculinity of the army, with its hyper-aggression and rigid conformity to the rules, molded those men into the taciturn fathers who struggled to express their love for their sons.

For gay cast members, that distance was especially troubling. “For any gay person, there is a relationship with shame. That’s something that you have to constantly negotiate,” said Hermanus. “It could come from your parents, it could come from society, it could come from yourself.”

The brutal war depicted in “Moffie” has somehow given the two generations common ground — the fathers as veterans, the sons as their onscreen doubles — offering an unexpected path to acceptance. “For the vast majority of those actors, coming out was horrific,” said Hermanus. “Making the film for [them] was an incredibly cathartic experience.”