(HarperCollins)

With his big Gandalf-style hat and white beard, Sir Terry Pratchett slightly resembled a shorter version of Tolkien’s famous wizard. He himself was certainly a wizard of the page, the most endearing comic novelist since P.G. Wodehouse. But, unlike Wodehouse, he wasn’t just funny; Pratchett was also a moralist. Throughout his tales about the half-medieval, half-Dickensian magic kingdom of Discworld, he skewered bigotry, jingoism, cruelty and every kind of intolerance and zealotry. At the close of “The Truth” (2000), for instance, he spoke up plainly for political and cultural diversity: “Pulling together is the aim of despotism and tyranny. Free men pull in all kinds of directions.”

Only 66 when he died this past March, Pratchett had been battling posterior cortical atrophy — a kind of early onset Alzheimer’s disease — since 2007. Despite this “embuggerance,” he managed, with help, to keep producing books, publishing a final “adult” Discworld novel, “Raising Steam,” in 2013 and now “The Shepherd’s Crown,” the fifth, and sadly last, of the thrilling adventures of the young witch Tiffany Aching.

Tiffany was first introduced in “The Wee Free Men” (2003), which opens with a powerful witch named Miss Tick detecting “a definite ripple in the walls of the world.” Could another realm or dimension be trying to break through? Fortunately, the occult signs indicate that there is another witch nearby. Yet when Miss Tick scries into a saucer of water, she glimpses only the 9-year-old daughter of a sheepherding family. But Tiffany Aching — as any adult reader of fantasy immediately knows and any child-reader will fondly hope — is no ordinary little girl.

As the story progresses, Tiffany’s life of babysitting and churning butter is overturned. Six-inch-tall blue men with red hair, wearing kilts, float down a nearby river in a little boat. Ravenous fairy-tale monsters lunge up from the roiling water. Sudden silences and blurs pervade the landscape.

When she finally encounters Miss Tick and her toad companion, Tiffany learns that the wee men are the fearsome Nac Mac Feegle, sometimes referred to as “pictsies” (typical Pratchett wordplay — pixies with the drunken, warlike habits of the ancient Picts). But what about the other disturbing stuff going on?

“ ‘Another world is colliding with this one,’ said the toad. . . . ‘All the monsters are coming back.’

“ ‘Why?’ said Tiffany.

“ ‘There’s no one to stop them.’

“There was silence for a moment.

“ ‘There’s me,’ said Tiffany.”

Even now, I feel a thrill just typing those words. At the conclusion of “The Wee Free Men,” Tiffany learns about the true nature of witchcraft from one of Pratchett’s most beloved characters, the greatest of all witches, Esmerelda Weatherwax. ”We look to . . . the edges,” says Mistress Weatherwax. “There’s a lot of edges, more than people know. Between life and death, this world and the next, night and day, right and wrong . . . an’ they need watchin’. We watch ’em, we guard the sum of things.”

In the subsequent books about Tiffany — “A Hat Full of Sky” (2004), “Wintersmith” (2006) and “I Shall Wear Midnight” (2010) — Pratchett follows the apprentice witch as she learns her craft and gradually reveals her mastery. Yet, like Granny Weatherwax herself, Tiffany spends most of her time just helping others as a midwife, herbalist and comforter to the sick and afflicted. Above all, she remains firmly connected to the soil and traditions of her home territory or “steading,” the Chalk.

When “The Shepherd’s Crown” begins, Tiffany has grown into a young woman, utterly devoted to her work but also hoping for a life with her friend Preston, currently a medical student in the capital city of Ankh-Morpork.

Pratchett quickly establishes three main storylines. In one, the gentle youngest son of Lord Swivel rebels against the brutal traditions of his father. Geoffrey loves animals, refuses to eat meat, abhors fox hunting — and possesses a strange power to calm and defuse tense situations. Seeking a purpose in life, Geoffrey eventually decides to become a witch. Of course, witches are traditionally women, but need they be? In a way, Pratchett here reprises the theme of “Equal Rites” (1987), in which a young girl felt it her destiny to become a wizard.

In his second storyline, Pratchett describes the quiet death of Granny Weatherwax and its consequences. The old woman cleans her little house, feeds her cat (whose name is You), and puts on her best witch’s dress. She carefully places two pennies on a small bedside table and leaves a short note. When Death — another of Pratchett’s most notable recurrent characters — comes for her, he asks why she was content to live in this tiny little country when she could have been anything and anybody in the world.

Granny replies sharply: “I never wanted the world — just a part of it, a small part that I could keep safe, that I could keep away from storms. Not the ones of the sky, you understand: there are other kinds.”

To which, Death — who always speaks in capital letters — answers, “A VERY GOOD LIFE INDEED, ESMERELDA.”

Granny’s note, discovered by her friend Nanny Ogg, reads in part, “All of it goes to Tiffany Aching except the cat, You. She’ll go where she wants to.” Despite the clear implication that Tiffany will become the leading witch of her time, the immediate result is that the overworked young woman must now look after both the Chalk and Granny’s steading. Shuttling back and forth by broom between the two, she is soon overextended and exhausted.

Meanwhile, the death of the most senior of the witches results in a weakening of the forces that guard Discworld. The kelda — or queen — of the Nac Mac Feegle warns Tiffany: “We mus’ watch the gateways, and ye mus’ tak’ great care. For them ye don’t wish to know might be seeking ye out.” The attack, we soon learn, will come from Faery, from the amoral, heartless elves whose dazzling glamour alone can leave adversaries feeling demoralized and defeated.

As the situation grows desperate, Tiffany encounters her old enemy, the Queen of the Fairies; the Nac Mac Feegle prepare for war; Geoffrey discovers a secret weapon; and the witches of Discworld cease their usual squabbling and assemble. When the Elvish armies finally pour through the gateway, they find waiting for them the indomitable Tiffany Aching and her friends.

“The Shepherd’s Crown” is certainly a worthy crown to Terry Pratchett’s phenomenal artistic achievement, though sharp readers will recognize that some elements — Geoffrey’s calming talent, the mysterious cat, You — are never fully developed. Moreover, anyone expecting lots of laughs will need to revisit some of the other books set on Discworld. While the Nac Mac Feegle are consistently amusing, much of this novel concerns itself with death and life’s purpose, while also examining the claims of tradition against the need for change and progress. Above all, though, “The Shepherd’s Crown” — like all of Pratchett’s fiction — stresses the importance of helping others. Beyond this, I think that Pratchett’s farewell advice would be to follow his witches’ sensible principle: “Just do the work you find in front of you and enjoy yourself.”

Michael Dirda is a regular book reviewer for Style and the author of the just-published “Browsings: A Year of Reading, Collecting, and Living with Books.”

The Shepherd’s Crown

By Terry Pratchett

HarperCollins. 276 pp. $18.99