Heidi is an orphaned girl initially raised by her aunt Detie in Maienfeld, Switzerland after the early deaths of her parents, Tobias and Adelheid (Detie's sister and brother-in-law). Detie brings 6-year-old Heidi to her paternal grandfather's house, up the mountain from Dörfli. He has been at odds with the villagers and embittered against God for years and lives in seclusion on the alm. This has earned him the nickname Alm-Uncle. He briefly resents Heidi's arrival, but the girl's evident intelligence and cheerful yet unaffected demeanor soon earn his genuine, if reserved, affection. Heidi enthusiastically befriends her new neighbors, young Peter the goatherd, his mother, Bridget, and his blind maternal grandmother, who is "Grannie" to everyone. With each season that passes, the mountaintop inhabitants grow more attached to Heidi.
Three years later, Detie returns to take Heidi to Frankfurt to be a hired lady's companion to a wealthy girl named Clara Sesemann, who is regarded as an invalid. The girl is charmed by Heidi's simple friendliness, and delights in all the funny mishaps brought about by Heidi's lack of experience with city life. However, the Sesemanns' strict housekeeper, Fräulein Rottenmeier, views the household disruptions as wanton misbehavior, and places Heidi under more and more restraint. Soon, Heidi becomes terribly homesick, and grows alarmingly pale and thin. Her one diversion is learning to read and write, motivated by her desire to go home and read to Peter's blind grandmother. Clara's paternal grandmother comes to visit the children and becomes a friend to Heidi. She teaches Heidi that she can always seek relief from misery by praying to God.
After months pass, the Frankfurt household is brought near hysteria by nightly sightings of what appears to be a ghost. When Clara's father and his friend the doctor keep awake one night to find out what is causing the disturbances, they see that the "ghost" is actually just Heidi, who's sleepwalking in her nightgown. The doctor sees that Heidi's under a great deal of stress. He warns Mr. Sesemann that if Heidi is not sent home promptly, she may become very ill. Soon, a joyous Heidi returns to the mountains, where she teaches her grandfather about the comfort of prayer. She reassures him that it's never too late to turn back to God. Her simple lesson prompts her grandfather to descend to the village and attend a church service for the first time in years, marking an end to his seclusion. He's heartily welcomed back by the church pastor and the villagers.
Heidi and Clara continue to keep in touch and exchange letters. A visit by the doctor to Heidi leads him to eagerly recommend that Clara visit Heidi. He feels assured that the fresh mountain air and the wholesome companionship will do her good. Clara makes the journey again the next season and spends a wonderful summer with Heidi and becomes stronger on goat's milk and fresh mountain air. But Peter, who grows jealous of Heidi and Clara's friendship, pushes her empty wheelchair down the mountain to its destruction (although he later feels guilty about what he did and confesses to it). Without her wheelchair, she attempts to walk and is gradually successful. Her grandmother and father are amazed and overcome with joy to see Clara walking again. The Sesemann family promises to provide permanent care for Heidi, if there ever comes a time when her grandfather is no longer able to do so.