When Heidi is eight years old, her Aunt Detie, who is working in Frankfurt, Germany, comes to see her. She takes Heidi to live in Frankfurt as a companion to a twelve-year-old girl called Clara Sesemann who is an invalid and is unable to walk.
Clara, her father, and her Grandmamma all become very fond of the little Swiss girl. However, Miss Rottenmeier, the Sesemann housekeeper, does not like Heidi because she has scruffy clothes, cannot read, and has not learnt how to behave in a grand house. Heidi does things which Miss Rottenmeier thinks are very naughty, like going out alone and bringing home some kittens.
As time goes by, Heidi becomes more and more homesick. Clara's Grandmamma sees that she is unhappy and suggests that Heidi should pray to God for help. She also makes sure that Heidi learns to read and gives her a picture book with stories from the Bible. But Heidi is still unhappy and she starts to sleepwalk; it is at this point that Clara's doctor, Dr Classen, insists that Heidi be allowed to return home.
Back in the mountains, Heidi shares her new belief in God with Grandfather. He is very moved and decides to start going to church again. He also arranges to live in the village during the winter so that Heidi can go to school. Dr Classen, Clara, Grandmamma and Mr Sesemann all travel from Frankfurt to visit Heidi. Clara is allowed to stay with Heidi in the hut on the mountain, and with Grandfather's help she learns to walk again. Peter the goatherd is angry with Clara for taking Heidi's attention away from him, so he pushes her wheelchair over a cliff into the valley below. However Grandmamma understands why he has done this. She knows that he feels guilty, so instead of punishing him she rewards him with some money. The Sesemann family give presents to Heidi and to Peter's blind grandmother in order to make her life more comfortable. They promise Heidi's grandfather that they will make sure Heidi is taken care of after his death.
The story ends with Heidi and Grannie talking together, and thanking God for all the good things He has brought into their lives.