Twelve-year-old David has lived in a concentration camp for as long as he can remember. While the people who run the camp are only referred to as them, later in the book it is stated that they came to power in 1917, indicating that the captors are Communists.
His only friend in the camp, Johannes, died some time before, but one of the commandant has been keeping an eye on David, making sure he is fed properly and taking his vitamins. This guard sets up the escape, gives him some soap, and leaves a sack outside the camp fence with bread, a bottle of water, and a compass in it. David must go south to Salonica, find a boat to Italy, then travel north to a free country that has a king.
David uses the excuse that he works for a circus to explain why he is a polyglot and why he is traveling (to catch up with the circus which has gone ahead). On his way, he helps people, and sometimes they give him money. Along his journey, David discovers the beauty of the world and slowly he changes his behavior and the way he interacts with people.
He saves a girl named Maria from a fire in a shed where she was trapped. David spends some time in Maria's family's house, where he sees a globe and learns about different countries. However, his knowledge of suffering and death worries the parents. David overhears them talking about him and leaves the house to travel north again. Some time later he sees a newspaper personal advertisement aimed at him and placed by Maria's family offering him a home, so he sends them a letter to reassure them that he is all right.
David has also been praying to the God of green pastures, and a priest explains that while some people say there are many gods, there really is only one.
When he meets Sophie, a middle-aged lady that lives in Switzerland and likes to paint as hobby, she asks David if she might paint him; later she invites David to have lunch with her in her house, and while he is there, David sees a picture of a woman in Denmark. Sophie tells him that the woman's husband and child were killed, but that one guard let the woman escape. He realizes he needs to travel to Denmark and find that woman because she is his mother. He also realizes that the guard, who became the commandant, saved him because he was in love with David's mother. However, he did not reunite them because she did not love him back, and he still felt a need for revenge.
When winter hits, he is held prisoner by a farmer who uses him for slave labor. But along with this he gets shelter until the snow melts. The farmer's dog keeps him company through the winter, and travels with him when he escapes in the spring. Later, the dog gives his life to distract some guards so that David can sneak over the border.
Finally he arrives in Denmark, and traces the woman through the telephone directory. When he knocks on her door, he simply tells her "I am David", and she knows he is her long-lost son.