If D.W. Griffith’s “The Birth of a Nation” was “like writing history with lightning,” as Woodrow Wilson described it way back in 1915, then Spike Lee’s “BlacKkKlansman” is the roll of thunder that was eventually sure to follow. The astonishing true story of one of the riskiest undercover investigations in American history — an improbable early-’70s case in which black police detective Ron Stallworth (John David Washington) applied for and was ultimately granted membership in the Ku Klux Klan — Lee’s latest is as much a compelling black empowerment story as it is an electrifying commentary on the problems of African-American representation across more than a century of cinema.

Backed by Blumhouse and “Get Out” auteur Jordan Peele, “BlacKkKlansman” is also the best thing the director has made in a dozen years (since HBO miniseries “When the Levees Broke”) and a welcome throwback to the days when Lee’s movies struck a nerve in the cultural conversation. Call it “How Spike Got His Groove Back,” and don’t be surprised if the movie — which premiered in competition at the Cannes Film Festival — proves to be one of the summer’s breakout hits, assuming Sundance sensations “Sorry to Bother You” and “Blindspotting” don’t exhaust the appetite for more contemporary black-lives-matter bombshells.

Opening with one of the most recognizable scenes from “Gone With the Wind” — that of Scarlett O’Hara stumbling through a train station filled with wounded Confederate soldiers — and building to a galvanizing four-minute montage of recent events that show how racism is alive and well in our country, “BlacKkKlansman” feels like Lee’s “Don’t just complain about it, do something” answer to the lack of stories featuring African-American leads today. Lee was an outspoken critic of Quentin Tarantino’s “Django Unchained,” slamming the director’s excessive use of the N-word (which features about four dozen times here), and his movie feels like a different kind of anti-racism revenge saga — one that is plenty stylized but based in reality and could reasonably be considered a positive example.

Presented as a kind of real-life Shaft, Ron Stallworth serves as a role model for audiences starved for black heroes on-screen: an activist who infiltrated not just the Klan but also the corrupt, racist system that was the Colorado Springs Police Department at the time, using his position to bring the organization out of the Dark Ages. Incidentally, “the Organization” is also what the Colorado Springs KKK branch calls itself, although this group of semiliterate rednecks seem anything but organized: At times, their amateur hate club comes across so inept that the movie veers into outright comedy, even if Lee insists that he was shooting for something more serious.

Ron’s story is nearly too strange to be believed, which is precisely what makes it so compelling (his memoir has long been out of print, making it tough to fact-check, though a tie-in version will be reissued in advance of the film’s Aug. 10 release date). Subjected to a disgraceful interview featuring many questions no white candidate would be expected to answer, Ron is hired to the Colorado Springs police force on a kind of provisional basis. At first, his chief (Robert John Burke) sticks him in the records room, though Ron has bigger ambitions and jumps at the chance to go undercover, even if it means potentially betraying his own people.

The rookie cop’s first assignment is to attend a meeting where the black students’ union at the local college has invited civil rights leader Kwame Ture (Corey Hawkins) to speak. Ron’s boss describes the ex-Black Panther and his followers — including a young Angela Davis type named Patrice (Laura Harrier) — as “a bunch of subversives,” but he has no choice but to go along for the mission, which Lee uses to deliver a supercharged Black Power speech, complete with many of Ture’s actual talking points, including a Hollywood-oriented critique of how he found himself rooting against the African characters in classic Tarzan movies.

Though Lee is just one of four credited writers on the film (David Rabinowitz and Charlie Wachtel are both white), the director is hyperaware of the way mass media shapes our view of the world, contributing a film whose principal agenda seems to be shaming the white-supremacist bigots — and then-Grand Wizard David Duke (Topher Grace) in particular — who would be most embarrassed to know that their group was infiltrated by a black man. And yet, there’s something amiss about Ron’s plan, since there’s no way he can show up to a Klan meeting without blowing his cover.

To pull off the deception, he recruits fellow cop Flip Zimmerman (Adam Driver) to be his body double at in-person meetings with the Klan, while handling the majority of the investigation over the phone, where he allows them to think he is white. This is a hugely impractical arrangement and one that requires Ron and Flip to work together closely in getting their stories straight. (Ron may have initiated the investigation, but it seems infinitely simpler to let Flip take the lead.) And yet, not only does it happen, but the case only gets stranger from there — as when Ron is assigned to serve as Duke’s security detail on a visit to Colorado Springs.

Wild as some of the movie’s twists may be, Lee needed a slick, attention-grabbing lead actor to reinforce the sheer audacity of Stallworth’s plan. Instead, Washington (who played a bit part in “Malcolm X” a quarter century earlier) is merely adequate — a solid if somewhat blank choice for a role that should’ve launched a career, the way Terrence Howard charmed in “Hustle & Flow,” or Chadwick Boseman impressed in the three biopics that landed him the “Black Panther” gig. By contrast, Ron’s character is defined more by his Afro than by the actor that inhabits it, whereas Driver (who’s gracious enough not to steal any of the scenes he shares with Washington) starts to feel like the lead by virtue of being the more conflicted performer.

These days, the go-to approach for fact-based films is gritty, handheld “realism,” and yet, Lee has always favored a more heightened impressionistic approach — one that reminds audiences that they are watching a movie. Still, as his budgets have fluctuated in recent years, Lee’s style has become increasingly erratic, resulting in such uneven serio-satires as “Chi-Raq” and “Red Hook Summer.” Following more than a decade of duds (his last hit was the slick if vacuous heist movie “Inside Man”), Lee desperately needed to push the Reset button, going back to what worked for him earlier in his career, and “BlacKkKlansman” does exactly that. While not as thematically ambitious as his recent work, the movie delivers a clear message: As the election of Barack Obama demonstrated, it is possible for an outsider to change the system from within, and as his successor reminds, progress can always be repealed, and racism in American is far from solved.