The storyline is episodic, reflecting the original serialisation of the novel. In 1905, the Waterburys are an affluent family who live in a luxurious villa in the suburbs of London. Charles Waterbury, the father, works at the Foreign Office. The day after Christmas, he is arrested on suspicion of being a spy. This is hidden from the rest of the family by his wife. The family become impoverished and are forced to move to a house called Three Chimneys in Yorkshire, which is near Oakworth railway station. When they arrive, they find the house in a mess and rat-infested. The three children, Roberta (known by her nickname Bobbie), Phyllis and Peter, find amusement in watching the trains on the nearby railway line and waving to the passengers. They become friends with Albert Perks, the station porter, and with an elderly gentleman who regularly takes the 9:15 train. To make ends meet, their mother works as a writer and also home-schools the children.
Mrs Waterbury falls ill with influenza. Bobbie writes to the gentleman, who delivers food and medicine to the house to help their mother get better. They are admonished by their mother for telling others of their plight and asking for assistance. The following day, a man is found at the railway station. He speaks a language they cannot understand. The children figure out he can speak French, in which their mother is fluent. Mrs Waterbury discovers the man is an exiled Russian writer who has arrived in England to find his family who had fled there. He stays at their house. Bobbie writes another letter to the gentleman, asking him to help in finding the exile's family, who are soon found.
One day, while watching the railway tracks, they notice there has been a landslide which has partially obstructed the tracks. The children fashion the girls' red petticoats into flags to warn the driver of the impending danger. The train stops due to their warning. The railway company and villagers hold a party for the children and thank them for their actions. The children are given lifetime train-passes and personalised engraved watches and are dubbed "The Railway Children".
The children find out that Mr Perks, the station porter, does not celebrate his birthday. They secretly ask for gifts from the villagers that he has helped in the past and deliver the gifts to his house. Mr Perks initially refuses the gifts as he does not accept charity. However, after the children explain that the gifts are from people that he has helped over the years, he thanks them for their kindness. In return the following day, he delivers old newspapers and magazines for them to read. Bobbie reads one of the newspapers and notices a story about their father being imprisoned. She discusses this with her mother who finally discloses that their father is in prison after having been falsely convicted of being a spy and selling state secrets. She speculates that a jealous colleague of his may be behind it. Bobbie again contacts the gentleman and asks him to help her father; he informs her that since meeting the children and reading about their father's case, he has been working to prove his innocence.
A group of youths are playing a game of paper chase which the children observe. One of the boys injures his leg in a railway tunnel and is helped by the children. He is taken to their house where he recuperates from his injuries. The gentleman visits their house and reveals that the boy is his grandson, Jim, 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 departs to his home.
After Jim's departure, the children remark on their long hiatus 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, with a strange prescience, 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 station platform, where in the silent lingering smoke she sees her father, who has just alighted onto the platform after being exonerated and released from prison. She runs to greet him shouting "daddy; my daddy!". They return to Three Chimneys and the family are reunited.
End credits
The entire cast break the fourth wall and perform a curtain call as the credits roll. The camera moves slowly along a railway track towards a steam engine which is decked in flags, in front of which all of the cast are assembled, waving and cheering to the camera. At the start of the credit sequence, a voice can be heard shouting "Thank you, Mr Forbes" to acknowledge producer Bryan Forbes. At the end, Bobbie Waterbury (Jenny Agutter) holds up a small slate on which "The End" is written in chalk.
Jenny Agutter as Roberta 'Bobbie' Waterbury
Sally Thomsett as Phyllis Waterbury
Gary Warren as Peter Waterbury
Dinah Sheridan as Mother, Mrs. Waterbury
Bernard Cribbins as Albert Perks
William Mervyn as the Old Gentleman
Iain Cuthbertson as Father, Charles Waterbury
Peter Bromilow as Doctor Forrest
Ann Lancaster as Ruth
Gordon Whiting as Russian
Beatrix Mackey as Aunt Emma
Deddie Davies as Mrs. Nell Perks
David Lodge as Band Leader
Christopher Witty as Jim
Brenda Cowling as Mrs. Hilda Viney
Paddy Ward as Cart Man
Erik Chitty as Photographer
Sally James as Maid
Dominic Allan as CID Man
Andy Wainwright as Desk Sergeant
Lionel Jeffries as Malcolm (Voice)
Richard Leech as Doctor (Voice)
Amelia Bayntun as Cook (uncredited)
Bob Cryer (Chairman of the K&WVR) as the guard of the train carrying Mr. Waterbury (uncredited)
Paul Luty as Malcolm (uncredited)
Graham Mitchell (K&WVR Guard) as Train Guard (uncredited)
based on the 1906 novel of the same name by E. Nesbit.