Australian actor-turned-director Joel Edgerton (“The Gift”) steps behind the camera for only the second time in his career with “Boy Erased,” a compassionate and, at times, upsetting account of a young man’s forced participation in a conversion-therapy program at the hands of his Baptist pastor father and devout mother. It’s a crucially important coming-of-age drama that will hopefully serve as a cautionary tale for those who believe that pseudoscientific treatment or spiritual intervention can actually “pray the gay away.”

Based on author Garrard Conley’s 2016 memoir of the same name, the film stars Academy Award-nominated actor Lucas Hedges (“Manchester by the Sea”) as Jared Eamons, a high-school teen from Arkansas who begins to question his sexuality. This is followed by a series of traumatic experiences — without the thoughtful and empathetic responses most would want from their family. When his conservative father Marshall (Russell Crowe) confronts Jared about a rumor, he denies it at first before admitting to having an attraction to men.

Turning to the counsel of “wiser” elders in his congregation, the consensus is that Jared should be sent to reparation therapy where he can be cured of his homosexuality, an idea he agrees to if only to placate his parents, including his mother Nancy (Nicole Kidman), who sits quietly to the side as her son is urged to renounce what the church believes is an immoral lifestyle.

Once in therapy and surrounded by young men and women also struggling with their sexuality, Jared starts to recognize that nothing justifies the cruelty he and the others are suffering through. While he doesn’t receive much pity from his dad, “Boy Erased” takes a turn toward a more inspiring narrative when his mom realizes the program is causing more harm than good. Kidman is brilliant as she transforms from an initially complicit woman who defers to her husband and the men of the church to someone who chooses to accept her son for who he is, despite the consequences that come with that decision.

Taking on double duty as director and supporting actor is Edgerton, who portrays Victor Sykes, the resolved leader of the therapy sessions. Like “The Miseducation of Cameron Post,” another gay-conversion drama that debuted earlier this year starring Chloë Grace Moretz (“Let Me In”), “Boy Erased” doesn’t simplify its characters into heroes and villains. It wants audiences to understand the complexities of the relationships, even though, occasionally, it feels like Edgerton keeps the viewer at arm’s length on an emotional level.

Nevertheless, “Boy Erased” is critical viewing, especially for those bigots out there who still think a person’s sexual orientation is a choice. It’s all worth it if “Boy Erased” is able to affect a few minds.