In 1905, the Waterbury family lives in a luxurious villa in the London suburbs. Charles Waterbury Iain Cuthbertson, who works at the Foreign Office, is arrested the day after Christmas on suspicion of being a spy, a fact hidden from the rest of the family by his wife. Now impoverished, they move to a house called Three Chimneys in Yorkshire, near the Oakworth railway station. Upon arrival, they find the house in a mess and rat-infested.
The three children Roberta 'Bobbie' Waterbury Jenny Agutter, Phyllis Waterbury Sally Thomsett, and Peter Waterbury Gary Warren find amusement in watching the trains on the nearby railway line and waving to the passengers. They become friends with Albert Perks Bernard Cribbins, the station porter, and with an elderly gentleman who regularly takes the 9:15 train. To make ends meet, their mother, Mrs Waterbury Dinah Sheridan, works as a writer and homeschoools the children. When Mrs Waterbury falls ill with influenza, Bobbie writes to the gentleman, who delivers food and medicine to the house to help their mother recover. Later Mrs Waterbury admonishes the children for telling others of their plight and asking for assistance. The following day, a man collapses at the railway station. He speaks a language no one understands, but the children discover he also speaks French, in which their mother is fluent. She learns from him that he is an exiled Russian writer who has arrived in England in search of his family. While he stays at their house, Bobbie writes another letter to the gentleman, and with his help the family is soon found.
One day, the children witness a landslide which has partially obstructed the tracks. The girls fashion their red petticoats into flags to warn the driver of the impending danger and the train stops in time. The railway company and villagers hold a party for the children, and they are given lifetime train-passes and personalised engraved watches. Now they are dubbed “The Railway Children.”
Discovering that Mr Perks does not celebrate his birthday, the children secretly ask for gifts from the villagers that he has helped in the past and deliver them to his house. Mr Perks initially refuses the gifts as he does not accept charity. However, after the children explain the true circumstances, he thanks them for their kindness. In return, the following day, he delivers old newspapers and magazines for them to read. There Bobbie notices a story about their father being imprisoned. She discusses this with her mother, who finally discloses that he has been falsely convicted of being a spy and selling state secrets. Mrs Waterbury speculates that a jealous colleague of his may be behind it. Bobbie again contacts the gentleman and asks him to help; he informs her that since meeting them and reading about the case, he has been convinced of their father's innocence.
Later a group of youths are engaged in a paper chase, which the children observe, and one boy injures his leg in a railway tunnel. Helped by the children, he is taken to their house to recuperate from his injuries. The gentleman visits their home and reveals that the boy is his grandson, Jim Christopher Witty, and thanks the family for looking after him. Jim and Bobbie grow close during his recuperation and promise to write to each other when he goes home.
After Jim leaves, the children remark on their long absence from waving at the train passengers and resolve to go to the railway the following morning. When they do so, all the passengers wave at them, and the gentleman gestures to a newspaper. Later, Bobbie excuses herself from her lessons and walks down to the station, where Perks hints that something special has happened. Confused, Bobbie stands on the platform, where in the lingering smoke she sees her father, who has just alighted after being exonerated and released from prison. She runs to greet him shouting “Daddy; my Daddy!” They return together to Three Chimneys, where Bobbie leaves him to a private reunion with his wife.