Spike Lee and Prince went back a long way. Apart from being friends and mutual fans for decades, the two worked together on Prince’s “Money Don’t Matter 2Night” video and, more famously, on the 1996 film “Girl 6,” which featured a soundtrack made entirely of music from across the artist’s career, along with a new song he’d written specifically for the movie.

And in the hours after Prince died of an accidental drug overdose in April of 2016, Lee threw an impromptu block party outside his Brooklyn office that ended up being live-streamed on CNN, and even got the cooperation of local police when it ran over the time he’d been allotted — that celebration has evolved into an annual event held in Brooklyn (read Variety’s coverage of the event here).

Thus, it’s not entirely a surprise that a rare Prince song is featured in Lee’s new film, “BlacKkKlansman,” which opens Friday. Variety’s Peter Debruge called it “the best thing Lee has made in a dozen years” and “an electrifying commentary on the problems of African-American representation across more than a century of cinema.” Based on the true story of an African-American cop named Ron Stallworth, who infiltrated the Ku Klux Klan in Colorado in the 1970s, the film is also an indictment of the Trump Administration and the rise of racism that has infected the United States since his election: It ends with footage from the 2017 white supremacist rally in Charlottesville, Va., in which a young woman was killed when a terrorist drove his car into a crowd of people; Trump later essentially defended the white supremacist demonstrators by saying there are “really good people” on both sides of that rally. As the footage plays, a rare Prince recording of the spiritual “Mary Don’t You Weep,” which will be included on the forthcoming posthumous album “Piano & a Microphone 1983,” a solo recording long available on bootleg that is being officially released by Warner Bros. and the artist’s estate next month (hear the song here).

“I knew that I needed an end-credits song,” Lee told Rolling Stone. “I’ve become very close with Troy Carter [the former Spotify executive who is also the entertainment advisor to the Prince estate, and led the company’s sponsorship of Lee’s 2017 Prince celebration]. So I invited Troy to a private screening. And after, he said, ‘Spike, I got the song.’ And that was ‘Mary Don’t You Weep,’ which had been recorded on cassette in the mid-‘80s.

“Prince wanted me to have that song, I don’t care what nobody says,” he continued. “My brother Prince wanted me to have that song. For this film. There’s no other explanation to me. This cassette is in the back of the vaults. In Paisley Park. And all of a sudden, out of nowhere, it’s discovered? Nah-ah. That ain’t an accident!”

He also spoke about why the song and the scene are essential to the film. “When Charlottesville happened, I knew that was going to be the ending [of the film],” he said. “I first needed to ask Ms. Susan Bro, the mother of Heather Heyer, for permission. This is someone whose daughter has been murdered in an American act of terrorism — homegrown, apple-pie, hot-dog, baseball, cotton-candy Americana. Mrs. Bro no longer has a daughter because an American terrorist drove that car down that crowded street. And even people who know that thing is coming, when they see it, it’s like, very quiet. People sit there and listen to Prince singing a Negro spiritual, ‘Mary Don’t You Weep.’”

“BlackKkKlansman” comes out on Friday.