In the Swiss Alps lives an antisocial old man, who everyone calls the Alm-Uncle ("Alm" means he lives on the mountain, and "Uncle" because he's distantly related to everyone in town). He once had a family, but there was a falling out and he hasn't heard from them in decades. Doesn't want to. Same thing happened between him and God; he's basically sworn off any unnecessary contact with his fellow man unless it's absolutely necessary. So the Alm-Uncle lives up there on top of the mountain in his small cabin, his only company being his goats and the occasional bit of gossip from Peter the goatherder. Everyone in the nearest town (except the local clergyman) hates and fears him because he's so antisocial.

Then one day his daughter-in-law's sister, Dete, stops by with his five-year-old granddaughter Adelheid, nicknamed Heidi, in tow, being her guardian since her parents' death. Dete wants to move up in the world by accepting a position as a hired servant in the city, so Heidi can't stay with her anymore. So she leaves the little girl there and flees back down the mountain.

The Alm-Uncle doesn't really like the situation, but he does figure out pretty quickly that Heidi is a smart child, respectful, polite, energetic, curious, and in all ways delightful. And it isn't long before they're as close as can be. Heidi loves living in the mountains and finds ever so many things to enjoy about the details of her life there. Gradually she gets her grandfather to rejoin his fellow men, moving down to the village during the winters.

That's about when Dete comes back and drags Heidi off to the German city of Frankfurt. Her boss has a rich friend who has a crippled daughter who wants a playmate. Dete's going to drag Heidi away for the finder's fee regardless of the girl's opinion. Heidi must be tricked into going, and the Alm-Uncle resumes his hermitlike ways.

Stuck in Frankfurt, Heidi does become friends with the other girl, Klara. But she aches to get back to the Alps, back to her grandfather. At first she thinks that her stay is temporary, but when she's informed that it's permanent, she begins to act out in ways that surprise even her. Klara's father means well, but business keeps him away a lot, leaving Klara and Heidi under the care of a borderline SadistTeacher named Miss Rottenmeyer.

Meanwhile Klara's grandmother makes a visit, and introduces Heidi to Jesus, the Bible, and prayer. And later on she puts it to Heidi that when God answers prayer, sometimes He does not say "yes" right away, but either "no" or "wait". That if God said "yes" at the wrong time, it would be a sorrowful thing, but if God in His wisdom says "wait" or even "no", then in due time it will prove to be better in all ways than if He had said "yes" back at the start. This philosophy forms a cornerstone for the rest of the book.

When the family doctor diagnoses Heidi with acute homesickness after he finds her [[HeroicBSOD sleepwalking and crying]], the family is forced to send her back to the Alps, to her grandfather. She goes scarcely believing that it is happening. Once she is home, her good health and vigor come back straightaway.

What is more, she brings lessons from the city. Her friend Peter had always thought reading to be too hard a task, and his attitude had convinced Heidi that it was impossible to learn; but Klara's grandmother opened up her mind and got her to learn reading practically overnight, and now Heidi will not rest until Peter learns (at least as far as his stubborn mind will let him). And Heidi uses a tale from her beloved storybook (given her by the grandmother), the tale of the Prodigal Son, to convince her grandfather to give God another chance - that no matter how long he has forsaken God, God will yet welcome him back with open arms. The two of them start going to church, where the Alm-Uncle makes up with the pastor.

Eventually, the family from Frankfurt visit the grandfather, and are thrilled to see Heidi in such good health again. Equally charming is the atmosphere, though it is a trying hike up the mountain from the town below. The grandfather proves that he is capable of caring for an invalid (a skill learned from caring for his crippled commander, back in the war), and persuades the family to let Klara sleep overnight in the cabin, a move greeted with delight by both girls. The family heads back down to the inn.

The next day, the children are about to enjoy a picnic with Peter. But jealousy burns inside Peter, for until now Heidi was his friend alone, and here has come this other child to take up her attention. In a fit of rage, he hurls Klara's wheelchair down the mountainside.

When Heidi discovers the wheelchair gone (but imagines that the wind took it), she is not deterred, but convinces Peter to help her support Klara as they walk up to the picnic site. Between this and the Grandfather's later attentions, Klara manages to strengthen her weak legs enough to walk, though it hurts terribly and she cannot do it unaided (yet).[[note]]Anyone reminded of ''Literature/TheSecretGarden''?[[/note]]

When the grandmother returns, she finds a Klara who bravely walks to her - on the Grandfather's arm - and she is so happy that she doles out treats. In the midst of this, the truth about the wheelchair comes out, but the grandmother takes it in stride as God's providence (providing reason for Klara to experiment with walking). Instead of punishing Peter, she rewards him with a little money, that works out to "two pennies a day"; when he misunderstands her as promising this for the rest of his life, she laughs and declares it will be written into her will, two pennies a day for him the rest of his life.

So Heidi understands with clarity the way things worked out for the best because God did not answer her prayer immediately, but let things happen in good time, no matter how much she hated to be away from her grandfather. And they all live HappilyEverAfter.