NEW YORK -- Stephen Sondheim writes musicals like no one else, so it is only natural that, drawing on the bedtime stories of our childhood, he would come up with a fairy tale musical like no other.

It is called "Into the Woods" -- those deep, dark woods through which Little Red Riding Hood skips on her way to Grandma's and Cinderella flees on her mad dash from the ball. Among other familiar presences on hand are the ravenous wolf, the wicked stepsisters, golden-tressed Rapunzel, Jack (who climbed the beanstalk) and two handsome princes, one of whom has the honesty to admit, "I've been raised to be charming, not sincere."

In previous incarnations, they braved the thorns, bested the monsters, dispelled the curses and lived happily ever after. In "Into the Woods," which opened last night at the Martin Beck Theatre, they are having a much harder go of it. Their innocence doesn't protect them, their wishes induce mostly frustration, and a giant is forever threatening to stomp them into the ground.

To survive in a threatening world -- suspiciously like our own -- they are going to have to grow up fast. Happily ever after really isn't the question. Survival is. Early on, Little Red Riding Hood learns to carry a knife in her basket along with the sweet cakes for Grandma.

For all the cockeyed and hilarious imagination it brings to the land of once-upon-a-time, "Into the Woods" is really a bittersweet affair. The perils of growing up, making choices and suffering the consequences have long preoccupied Sondheim. As far back as "Company" in 1970, he was pondering the difficulties of "Being Alive." He's still at it -- this time in collaboration with James Lapine, who has written the book for "Into the Woods" and directs the sumptuous production.

Contradictory as it may sound, they are trying to spin enchantment out of disenchantment. Playfully, they're insisting that the playpen is booby-trapped. While they kick up their heels, one of Cinderella's stepsisters, in her desperation to fit the slipper, lets a toe be whacked off with a sharp blade. "Annie" it's not. If Daddy Warbucks turned up in these woods, he'd probably be a pedophile. This is a fable for adults -- who tend to believe more readily in vengeful witches than in benevolent fairy godparents anyway.

Since the witch, a crook-fingered hag who is later metamorphosed into a luscious woman, is incarnated by Bernadette Peters, such a belief is easily justified. Peters is only one of many who shine in this endeavor (wryly suggestive of Paul Sills' lickety-split Story Theatre productions), dressed up to the nines or maybe the tens by costumer Ann Hould-Ward.

Those who have been waiting for Sondheim to return to the melodic charms of "Follies" or even "Merrily We Roll Along," however, will have to continue to wait. The score relies heavily on the pointillist recitatives he employed in "Sunday in the Park With George." The music is lovely, but it has the fleeting quality of wood smoke, blowing across the stage, rustling leaves and stirring up vague feelings of yearning and regret. What predominates -- on first hearing, at least -- are Sondheim's lyrics. Mother Goose, had she been a member of Mensa, might have turned out verse like this -- perspicacious, witty, paradoxical and, of course, rife with the very rhymes you don't expect.

As in Shakespeare's forests, the elegantly filigreed woods, designed by Tony Straiges, serve as a meeting ground for characters who wouldn't meet otherwise. To assure that eventuality, Lapine has concocted his own fairy tale to add to the mix. It's the story of the baker and his wife, doomed by that cantankerous witch to a life of sterility. If they are ever to have children, they must first produce a cow white as milk, a cape red as blood, hair yellow as corn and a slipper fine as gold.

Since the cow belongs to Jack, the cape to Red Riding Hood, the hair to Rapunzel and the slipper to Cinderella, everyone gets drawn into the saga before long. The baker and his wife (Chip Zien and Joanna Gleason, and both irresistible) are bound and determined to procure the specified objects, even if it means throwing a monkey wrench in the lives of characters who are struggling to follow their traditional destinies.

Jack, for instance, is reluctant to part with his treasured cow, Milky White, for a mere handful of beans. The baker's wife presses her arguments cannily, concluding, "If the end is right, it justifies the beans." She gets the cow. The fun of the first act comes from Sondheim and Lapine's turning old tales upside down -- sometimes with a touch of ghoulish glee -- and yet still having them come out right in the end.

But the woods are not just where you venture in search of fortune. They are also the preserve of death and destruction. The miraculous concatenation of events that can result in unimaginable happiness -- or a hen that lays golden eggs -- can also awaken demons. Jack slays the giant in the first act, as he's supposed to. But there's still the giant's mother to reckon with in the second. We never see her, but the stage rumbles with her heavy footstep and she casts a dark shadow over huddled mortals, who suddenly look very small and very lost.

Characters who thought they'd come to the end of their stories find themselves, once again, forced to go back into the woods to protect their sanity and keep chaos from the doorstep. "Giants never strike the same house twice," says Jack's mother, played with splendidly droll exasperation by Barbara Bryne. But, of course, she's wrong. The giants never go away -- they're just held at bay temporarily and at a huge cost.

Indeed, the ranks are severely depleted at the end of "Into the Woods." The survivors, looking to explain the carnage, take what solace there is in the thought that "No One Is Alone." The number is a poignant expression of solidarity in troubled times. Gestures do count. Someone is on your side. "No one leaves for good." The battered characters are trying hard to believe. So, one suspects, is Sondheim.

And so are we. The uplift is tentative, hesitant, maybe only the final wish in a show strewn with wishes. However, this cast constitutes such a marvelous ensemble, united by uncommon talent and a manifest love for what they are doing, that the message comes through. The interconnectedness Sondheim wants to celebrate as our only defense against the dark has been practiced all evening long by the players themselves.

Gleason has an appealing take-charge pragmatism as the baker's wife, who discovers to her delight that her husband is more of a man than she suspected. And indeed, Zien grows from a nobody, dusted with flour, to a battle-scarred somebody. Danielle Ferland's Little Red Riding Hood, a pudgeball with sausage curls, could be Shirley Temple's petulant sister. She's got path smarts, if not street smarts, and when the satyrlike wolf (Robert Westenberg) accosts her, it's not immediately clear who's going to get the best of whom.

Carrot-topped Ben Wright makes a sweetly benighted Jack, his wits as dim as his eyes are wide, while Kim Crosby gives Cinderella an amusingly klutzy side (how else could she lose that slipper so easily?) and a distracted air that comes from "being pursued" when she's "not in the mood." Westenberg is her Prince Charming, but Rapunzel also has a noble suitor, played by Chuck Wagner. In one of the show's funniest numbers, the princes confess to preferring the ecstatic "Agony" of the pursuit over the bliss of the catch.

But then, everybody is discovering that wishes aren't all they're cracked up to be, especially when they come true. "Into the Woods" may be filled with magical effects -- chess-set castles that rise from the ground, carrousel horses towing gilded carriages, and puffs of cumulous smoke marking apparitions and disappearances. But sooner or later, the magic goes dead and the clouds dissipate.

Anyone can lead a charmed life. What do you do, this probing and altogether unconventional musical wants to know, when the wand doesn't work any more and the woods are growing chilly?

Into the Woods. Music and lyrics by Stephen Sondheim; book by James Lapine. Directed by Lapine. Sets, Tony Straiges; costumes, Ann Hould-Ward; lighting, Richard Nelson; orchestrations, Jonathan Tunick; musical staging, Lar Lubovitch. With Bernadette Peters, Joanna Gleason, Tom Aldredge, Chip Zien, Robert Westenberg, Barbara Bryne, Kim Crosby, Danielle Ferland, Ben Wright, Chuck Wagner, Edmund Lyndeck. At the Martin Beck Theatre in New York.