David Milch’s short-lived and long-lamented HBO western “Deadwood” gets a belated series finale this Friday night, some 13 years after being unexpectedly canceled just before production was to begin on the show’s fourth season. For more than a decade, fans left dangling by season three’s abrupt, unresolved ending have clung to whispers and rumors of a two-hour movie that would wrap things up — an undertaking that seemed impossible given the scale of the production, plethora of plotlines and busy schedules of its sprawling ensemble cast. The fact that “Deadwood: The Movie” even exists at all is something of a logistical miracle. That it turned out to be this terrific is cause for celebration.

“It is my considerable happiness to see you again,” swoons Molly Parker’s twice-widowed Alma Ellsworth upon being reunited with her long-ago lover, Sheriff Seth Bullock (Timothy Olyphant), “as if a dream might come alive to draw breath.” For die-hard fans, these 110 minutes will feel very much like a dream indeed, one full of fond, familiar faces in which old wrongs are righted, amends are made and everyone takes a turn on the dance floor before getting a proper, sentimental sendoff. But none of this comes easily. It’s still “Deadwood,” after all.

Dayton Callie (left) as Charlie Utter and Molly Parker as Alma Ellsworth in "Deadwood: The Movie." (Courtesy Warrick Page/HBO)

When it premiered in 2004, the program became instantly notorious for its pungent period details, blunt sexuality, graphic violence and, above all, the soaring arias of profanity carried to Shakespearean heights by Ian McShane’s aptly named Al Swearengen. (His breathtaking deployment of a certain 10-letter obscenity proved astonishingly adaptable to all parts of speech, notably thriving in gerund form.) Yet for all the cussin’ and bloody tusslin’ in the muck, “Deadwood” viewed its filthy mining camp full of misfits, hoopleheads and whores with uncommon generosity.

Even Swearengen — a vicious pimp and unrepentant murderer — turned out to have hidden streaks of kindness and decency underneath his soiled long-johns and pinstripe suit, brilliantly manipulating characters and events to protect the burgeoning town’s best interests while outwardly insisting he was only looking out for his own. Say what you will about the ill-mannered, potty-mouthed people of Deadwood, they had a knack for rising to the occasion when least expected. It was an R-rated story with a G-rated heart, about folks who can’t help but come together and look out for one another, which is how civics and civilizations are born.

The series ended in exactly the wrong spot, with the camp brought low and complicit in the killing of an innocent in order to appease murderous millionaire George Hearst, played by the terrifying Gerald McRaney as a rapacious, drawling creature of unfettered capitalism. The final shot found Swearengen on his hands and knees, trying to scrub a blood puddle from the floor as it spread like a stain upon the community’s collective soul. As an ending it felt agonizingly incomplete, not to mention antithetical to Milch’s humane, optimistic worldview. You finish the show yearning for a redemption that was never able to be filmed. Until now.

“Deadwood: The Movie” picks up in 1889, 10 years after the shattering events of season three. Our muddy mining town has flourished into a full-fledged mini-metropolis, complete with telephone poles studding the streets and buildings made of brick and stone. The thoroughfare is filled for a celebration of South Dakota’s induction into the United States of America — an event bringing together old friends and enemies, including the aforementioned widow Ellsworth and our repugnant villain Hearst, now the junior senator from California.

Gerald McRaney (pictured standing in the horse carriage) as George Hearst in "Deadwood: The Movie." (Courtesy Warrick Page/HBO)

Watching over the town from the balcony of his brothel, as always, is McShane’s shockingly frail Swearengen, waylaid by an over-abused liver and nearing death’s door. “It’s the dispatch I find inglorious,” he confides to Brad Dourif’s kindly Doc Cochran. But Al’s not exactly going gently into that good night, railing with blasphemous brio against the indignities of infirmity while lamenting the loss of his famous libido, though admittedly he’s “become more and more forgetful of what that whole sordid business is to signify.”

Hearst’s return rips open old wounds within the camp, and his rapidly expanding telephone business requires stringing poles across land owned by our beloved Charlie Utter (Dayton Callie), the avuncular, tortoise-eyed gentleman sidekick to the late Wild Bill Hickok and just the kind of fellow who would get a kick out of being “the lone holdout to the path of progress.” Bullock tries to warn him of “the bastard’s disposition to foul play” while Al assures us it won’t be long before Hearst “honors the rigors of his putrid [expletive] nature.”

More straightforward in its plotting than the often-labyrinthine series, “Deadwood: The Movie” nonetheless manages to incorporate several moments for each member of its massive cast to shine. Paula Malcomson’s mouthy, former prostitute Trixie is expecting a child with John Hawkes’ stalwart Sol Star, while Robin Weigert’s booming baritone Calamity Jane has come back to declare her true love for Kim Dickens’ fancy madam Joanie Stubbs. Ferreting around underfoot is the “titular” Mayor E.B. Farnum, played by William Sanderson with weaselly aplomb, and the Chinatown alleys are still run by Keone Young’s Mr. Wu, whose carnivorous pigs never go hungry when this crew starts kicking up dust. It will be your considerable happiness to see them all again.

Most improved is Timothy Olyphant, who during the original series sometimes struggled with the demands of his role as a rage-case lawman learning to channel his brutish tendencies into the self-righteousness provided by a badge. Maybe it was his six seasons playing a much cooler-under-the-collar TV cowboy on the excellent Elmore Leonard spinoff “Justified,” but Olyphant has developed an easy authority that feels refreshingly mature, bringing some touching pangs of regret to Bullock’s scenes with the widow Ellsworth.

Ian McShane as Al Swearengen in "Deadwood: The Movie." (Courtesy Warrick Page/HBO)

Looming large over the production is creator David Milch’s recent revelation that he’s been diagnosed with Alzheimer’s. The hard-living, poetically profane Al Swearengen always seemed an authorial stand-in to begin with, pulling strings to orchestrate the events of the show while offering wry play-by-play commentary from his balcony for the audience’s amusement. Al’s reckoning with his impending mortality has the searching, personal quality of a writer attempting to set things right in his fictional universe as a way of finding peace on his own way out. “We’re — all of us — haunted by our own [expletive] thoughts,” McShane intones with a hint of a smile. “Make friends with the ghost. It ain’t going [expletive] anywhere.”

In addition to the expected shootouts, screwing and swearing, “Deadwood: The Movie” prominently features a childbirth, a funeral and a wedding, taking a little extra time to linger within these milestones and celebrations of a community that, over 36 hours of television, grew so very dear. Twice within its final minutes, the film returns to close-ups on two pairs of hands entwined in compassion — one male and female, the other black and white. As is custom in these South Dakota hills, it’s those you least expect who become what one character calls “the showing-up sort.” Another wisely praises “them be thought least likely… their defects notwithstanding.”

“Deadwood: The Movie” airs Friday, May 31 on HBO.