It is a bright sunny day on Sodor, as Thomas chuffs along his branch line with Annie and Clarabel. When he sees Bertie, he decides to have a race with him, but nearly gets into trouble along the way, narrowly avoiding rail work and nearly having a head-on collision with Toby when he passes a red signal. Bertie believes that he will win, due to him being in first place for the majority of the race, but his chances of winning become slim when he has to slow down for Oliver the excavator, who is slowly trundling along the small countryside road. Thomas gets the upper hand in the race and Bertie finally gets past Oliver, who takes a shortcut, passing by a familiar man on a bicycle. When Thomas stops at Ffarquhar, he is very pleased with himself for winning, but Annie and Clarabel are not pleased and sternly scold him for racing, but he just ignores their scolding, remarking he has raced on his branch line for years. Bertie arrives at the station, cross that he has lost, remarking that ever since the new branch line's construction site, he has been held-up by construction vehicles. Annie and Clarabel fear their branch line will be closed in favour of the new one, but Thomas dismisses it.
Meanwhile, Marion is on her way to the construction yard, fascinated by the enchanted scenery of the forest at Arlesburgh. As she chuffs along, two small engines dart pass her, taking her by surprise. She shuts her eyes and bumps into Toad and Oliver, who are waiting at the ballast chute. A small red engine races up the chute with some hoppers, frightening Marion. Toad introduces Marion to Rex, Mike and Bert, three miniature engines. Marion is interested by the little engines' size, asking if they are real. A cross Mike tells her they are real and that they deliver ballast, wool and passengers for the big railway. Toad and Oliver then leave for the construction yard, just as two black engines race past Marion.
At the construction yard, Duck is shunting trucks, just as Donald and Douglas arrive. Duck is delighted to see them, remarking that it has been ages since he has last seen them, but the twins tell him they have only been away to fetch new rails and sleepers for the construction. Meanwhile, Jack and Alfie are getting to work, just as Oliver arrives, apologising for being late as he took a wrong turn.
The next morning, Thomas cannot wake up. His fire goes out and there is not enough steam to get him going. The other engines all wake him up, reminding him that he needs to shunt Gordon's coaches, but Thomas is in no hurry to do that. Meanwhile, Gordon grumpily waits at Knapford for Thomas, just as he finally arrives. Annie and Clarabel remind Thomas it is time for their first train, but Thomas tells them he has to get Gordon's coaches first, criticising Gordon for being lazy for not getting his own coaches. Gordon tells Thomas that he knows full well that tender engines are too large for shunting, telling him that is what common little tank engines do. Determined to prove Gordon wrong, Thomas decides that he will pull the express today and thunders out of the station with the coaches. Unfortunately, due to being behind the coaches, this results in an accident occurring when he fails to slow down, collides with Emily as she tried to stop to avoid being hit, and leading to the express coaches coming off the rails.
Meanwhile, at the construction site, Marion tries to play 'Guess What's in My Shovel' with Donald, but he does not have time to play. She then turns her attention to Oliver the excavator, but he tells her that all he has in his bucket is dirt and rocks. When she asks what his name is, Marion is surprised to find out that the excavator's name is Oliver, believing that he turned himself from a railway engine into a digger. Oliver tries to explain the situation to her, but his attempts to do so are futile, as she believes the Arlesdale engines really are magic and granted him a wish, deciding that she will make a wish as well.
Back at Knapford, the Fat Controller has arrived to inspect the damage. Thomas tries to pin the blame on Gordon and Emily, but the Fat Controller does not believe him. He tells Thomas that he will be sending him to the construction yard as punishment. When Thomas asks who will look after his branch line, a new purple tank engine called Ryan shows up. The Fat Controller welcomes Ryan to his railway, while Thomas looks on, shocked.
At the construction site, work goes on as usual. However, trouble arises when the ground beneath the tracks begins to crumble and the workmen flag down Donald just before he can pass over the line. Some engineers are called and after inspecting the area of bad track, they deem it unsafe, forcing the workmen to re-route the line.
Meanwhile at Arlesburgh Junction the small engines are delivering ballast for the new branch line, when Thomas sadly puffs in. When asked what is wrong by Bert, Thomas crossly tells them about Ryan replacing him and what Gordon told him. The small engines tell him that bigger engines always act superior than smaller engines, even if they come out on top. The small engines then burst into song to cheer Thomas up, but unknowingly make him overconfident. When Thomas arrives at the construction yard, he remembers what the small engines told him about rails and sleepers coming before ballast and eagerly shunts some flatbeds of sleepers and rails along to the construction site. The workmen try to stop him from travelling along the unstable track, but Thomas thinks they are cheering for him. He bursts through the safety barriers and rolls over the unstable ground, just as it gives way and a large sinkhole forms. Thomas tries to escape the hole, but the trucks pull him in as his crew jumps clear. Thomas is badly damaged by the fall, but sees an abandoned pirate ship in the cavern.
At Knapford, Ryan arrives in the yard, introducing himself to Annie and Clarabel, who wonder where Thomas is. Meanwhile, at the cavern, Thomas is lifted out by Rocky, the Fat Controller reprimanding him for ignoring the danger signs. Thomas tries to tell the Fat Controller he was not responsible for the accident and tries to tell him about the pirate ship, but the Fat Controller is not interested in his excuses, telling Emily to send him to the Steamworks. As this goes on, an elderly man watches Thomas being recovered from the cavern with his telescope, stomping on his sailboat for bobbing about in the water.
Thomas is sent to the Steamworks, but is in no hurry to get back to work, telling Victor and Kevin that the Fat Controller has already replaced him. However, Victor reassures Thomas that the Fat Controller would never replace him and that he wants him to get back to work as soon as he can, while Kevin tells Thomas that despite all his accidents, he still works at the Steamworks. Just then, Edward arrives and tells them that Rocky has discovered the pirate ship, much to Thomas' fury. At the sinkhole, Rocky lifts the pirate ship out, much to everyone's amazement. Jack believes that the ship was put into the cavern by being folded up like a ship in a bottle, but Donald and Douglas dismiss Jack's theory, believing that the cavern must once have been open to the sea and the ship must sailed in then. Marion believes that if there is a pirate ship around, then there must be buried treasure. This gives her an idea for a wish and she sets off to Arlesburgh Junction at once.
At the junction, the small engines are still at work, just as they hear Marion coming. Both Rex and Bert immediately flee, leaving Mike behind. Before he can get off of the chute, however, Marion stops him and begins telling him her wish. Mike immediately breaks free and escapes, but this only fuels Marion's belief that the small engines are magical. Meanwhile, Donald and Douglas deliver the pirate ship to Arlesburgh Harbour, the same man and sailboat from earlier watching them.
That night, Henry is pulling the Flying Kipper, when he suddenly sees a white sailboat gliding down the rails. Surprised, he runs down a siding and hits the buffers, but when he looks back, the boat has gone. The next morning, he tries to tell the other engines at Brendam Docks, but most of them think he was just seeing things. Salty then shows up and tells the engines the legend of the Lost Pirate, Captain Calles, who was a feared pirate who stole much treasure from merchant ships. However, his activities gained attention from the Navy, who hunted him down. To escape from them, Calles sailed his ship into a cavern and buried his treasure nearby. However, his map revealing the location of the treasure was lost and he never found either the map or the treasure again. Salty says that the Lost Pirate is still out there on his ghostly ship, trying to find his treasure, but Cranky scoffs at the idea of a ghost pirate. The other engines all leave, with Henry still protesting that he saw the ghost. Meanwhile, Thomas passes through Arlesburgh when he sees the pirate ship, angrily saying that he was the one who found the ship, not Rocky. While he is not looking, the man from earlier climbs onto the ship and looks around.
Thomas arrives back at the construction yard and fills up on coal, surprised to find Ryan there. He asks the Fat Controller if he can now go back to his branch line, but the Fat Controller tells him that Percy is already doing his work and tells Thomas to collect some more ballast, leaving Thomas to lament at the fact he is no longer the Fat Controller's No. 1 engine. Meanwhile, Marion is helping Oliver and Alfie dig at a cliffside, telling them about how she made a wish to Mike.
When Thomas arrives at Arlesburgh Junction, he is blowing sparks and black smoke from his funnel. The small engines conclude that he must have had some bad coal. That night, he takes on some fresh coal and heads to the sheds, but finds Ryan already there. Ryan tries to coax Thomas into the shed, but Thomas chooses to sleep on a siding by himself, upsetting Ryan. As he sleeps on a siding, he suddenly wakes up to see a sailboat sailing along down the line, so he decides to follow after it. Thomas stops at the sinkhole to find the sailboat and its owner there, accidentally getting their attention. The man turns his attention to Thomas and asks him who he is, to which Thomas introduces himself and mentions how he found the pirate ship, but Rocky stole the credit from him. The man introduces himself as Sailor John, while his sailboat also introduces himself as Skiff, telling Thomas that they are looking for treasure. Sailor John asks Thomas if he would like to help him find the treasure, to which he agrees to. Tying a harness around his waist and to Thomas' buffer, Sailor John lowers himself into the cavern. Skiff tells Thomas that they have been sailing around the coast for years to find the treasure, as well as telling Thomas about how Sailor John gave him rail wheels to search for the treasure on land. Sailor John finds Calles' map inside of the cavern and is pulled back out by Thomas. Skiff reminds Sailor John that the sun is rising and John tells Thomas that he and Skiff have to go back home, telling him they forgot their shovels. Since Skiff cannot move due to there being no winds, Thomas pushes him along back to the harbour, where he sails off with Sailor John back home.
Later that morning, Thomas returns back to the construction yard, just as Ryan begins questioning him on his whereabouts the previous night. Thomas tells Ryan that he must have been having a dream and then questions him when he begins to fill up with coal. Thomas knows fully well that the coal in that hopper is bad, but does not say anything to Ryan about it. Meanwhile, Marion tries to work on the next cutting, but the rock is too hard. When told that they have to wait for a train of dynamite from Brendam Docks, Marion suggests to Oliver that he should make a wish and turn back into an engine, but Oliver, going along with what Marion says, tells her that may not work. When Ryan returns, he is emitting black smoke and sparks from his funnel. Just as he begins to puff away, sparks from his funnel set the dynamite in one of his trucks alight, leading him to panic. This causes him, Jack, Alfie and Marion to pass around a crate of dynamite with a lit stick, until it lands back into the trucks. Quickly thinking, Thomas buffers up to the trucks and shunts them into the cavern, causing the dynamite to explode. He is congratulated by the others, but the Fat Controller is furious, due to the scenario looking like Thomas was chasing Ryan with the lit dynamite and, fed up with Thomas having caused so much confusion and delay, sends him to his shed for the rest of the afternoon, along with ordering everybody else to go back to work. But this makes Little Bear, Brian, and Sylveon fed up with Sir Topham Hatt's stubbornness and they argued with him, but it was no good till Sylveon calls him a "fat moron". And Sir Topham Hatt angrily demands that they want Little Bear, Team Griffin/Eeveelution Family, and their friends out of the island till the new branch line is complete. The diggers attempt to continue work on the cutting, but without dynamite, work is slow. Marion finds a chest in the cliffside and tries to tell Alfie and Oliver, but by then, they have already left.
That night, Thomas rests on a siding, just as he sees Skiff and Sailor John heading back to the sinkhole. He follows after them and agrees to help them try to find the treasure. But no matter where they look, they cannot seem to find them. Sailor John immediately accuses Thomas of finding the treasure first, citing that only they and Skiff have seen the map and he has been with Skiff night and day. Skiff reminds Sailor John the sun is rising and Sailor John leaves as Marion wakes up. Upset, Thomas puffs away, but Marion bumps into him, causing her to dump the chest on him, revealing its contents - the treasure! The Fat Controller is delighted with Marion's discovery and plans to display the treasure in the museum, while he sends Thomas to the waste dump to deliver some construction waste.
As Thomas puffs along the cliffs, Henry thunders past, frightened by the Lost Pirate. As he rounds the bend, Thomas finds that the Lost Pirate is actually Sailor John and Skiff. Sailor John demands to know where the treasure is. Thomas tells him that the Fat Controller has it and plans to give it to the museum, infuriating Sailor John, despite his previous claims to Skiff that the treasure would go there. Sailor John angrily proclaims that he will get the treasure back, but Thomas stands up to him, telling him that the treasure doesn't belong to him then shoving him and Skiff aside, leaving John to pout.
Thomas returns to Knapford, where he overhears the Fat Controller speaking on the phone about the treasure. The Fat Controller says that the treasure will be stored at Knapford overnight, worrying Thomas. He returns to the construction yard, where he meets Ryan again. The two make amends for what happened earlier and Ryan once again tries to offer Thomas a space in the shed, but Thomas tells him he plans to stay at Knapford.
That night, Thomas sleeps on a siding outside of the station, waiting for Sailor John and Skiff to show up. Hours later, as he is asleep, Skiff and Sailor John arrive. Skiff asks what they are doing, but Sailor John does not tell him. John then jumps off of Skiff, hides from a passing Henry and then blows up the Fat Controller's safe with a stick of dynamite and steals the treasure. Skiff wants to have no part in his scheme, but has no choice but to follow along. The explosion and Sailor John stomping on Skiff wakes Thomas up, who begins pursuing him, albeit having troubles steaming up.
At Tidmouth Sheds, Henry races past, frightened by Skiff and Sailor John, who follow along shortly afterwards. Annie and Clarabel believe they are having a strange dream, until Thomas thunders past, chasing after Sailor John and Skiff. In order to keep up with them, Thomas has to race through a red signal, almost colliding with Gordon and a late-night express. Thomas heads through a tunnel and up a hill, where he finds the pirate ship there and tied to Skiff. Sailor John picks up the anchor and lets the ship roll down the hill. Meanwhile at Arlesburgh Junction, Ryan's worry about why Thomas stayed at Knapford prevents him from sleeping and he panics when he sees the ship approaching. Thomas passes by and tells the small engines to stop the ship. Though Sailor John scoffs at the engines' miniature size, the three small engines bravely push some ballast hoppers off of the chute and onto the standard gauge line. Most of the hoppers are shoved aside, but one gets stuck under the flatbed and causes the pirate ship to lose momentum. A rope then gets fastened to Ryan's buffer and the tank engine suddenly brakes, hitting a buffer stop and causing the ship to topple over. Thomas congratulates Ryan and puffs on.
As the morning sun rises, the chase is still going on. Thomas tries to tell Skiff to stop, but he cannot. Sailor John tries to stop Thomas, attempting to throw an anchor and shovel at him. He then tries to destroy Thomas by blowing him up with dynamite, but Skiff tips over slightly, causing John to lose his aim. Skiff encourages Thomas to derail him, just as John violently hits Thomas in the face with the oar, threatening to have Skiff in the dry dock sail-less. Thomas furiously bumps into Skiff, but accidentally sends him down a different line, much to Sailor John's delight. Though it seems as if there is no hope left, Thomas suddenly notices that his line crosses over Skiff's, immediately picking up speed and ramming into him. Skiff is re-railed onto Thomas' line, but their relief is short-lived, just as Thomas notices the line runs into the sea. Thomas falls into the sea and rests atop of Skiff's chassis, while Skiff and Sailor John sail away. Skiff tries to tell Sailor John to go back and help Thomas, but John threatens to destroy him if he tries to betray him. Suddenly, a wave pushes them along and causes them to lose the oar. Sailor John orders Skiff to stop it, telling him he is letting in water, but Skiff tells him that the treasure is too heavy and is making him sink, telling John to throw it overboard. Sailor John does not want to and forces Skiff to sail on, just as a huge wave forms. Skiff is capsized by the oncoming wave and the treasure chest sinks to the bottom of the sea. Thomas watches on from the harbour, thinking this is the end of Skiff, just as Skiff turns back over.
Later that morning, the police caught Sailor John and arrest him. Sailor John tries to tell the police, why he is innocent, but one police man tells him, that he's under arrest. Thomas is lifted onto a flatbed by Rocky and upon seeing the Fat Controller, he tries to apologise, thinking that he would be cross with him, especially after Thomas' previous mishaps. However, the Fat Controller tells Thomas that he is proud of him for trying to stop Sailor John and that Ryan told him everything. Thomas is still upset that the treasure is lost, but the Fat Controller is not concerned about that, telling Thomas that he's just happy he is alright and that his engines are more important to him than any old treasure and that Thomas is his No. 1. Thomas smiles and his number is shown to be back. And Little Bear, Brian, and Sylveon apologize to Sir Topham Hatt of what they said about him, but Sir Topham Hatt apologizes to them and tells them that they can stay on the Island of Sodor as long as they like.
At last, the construction of the new branch line running to Harwick is now complete. Marion finds out that there are, indeed, two Olivers on Sodor and Thomas, fully repaired, arrives with Annie and Clarabel for the opening ceremony. The Fat Controller announces that Ryan will be handling the goods traffic, while an old friend looks after the passengers. Thomas says he already has a branch line, but the old friend is revealed to actually be Daisy. The branch line is declared open and Thomas and the other engines steam along down the new line, meeting up with Skiff again, who is now carrying railboat tours. Divers recover the treasure and that night, Thomas and Skiff watch from the harbour as fireworks go off.
- Team Griffin/Eeveelution, The Griffin Family, Vinny Griffin, Glenn Quagmire, Cleveland Brown, Joe Swanson, Mitzi, No Feet, Tutu, Doug Funnie, Skeeter Valentine, Roger Smith, Bender Bending Rodríguez, Minerva Mink, Wubbzy, Widget, Walden, and Daizy guest star in this film.
- Dynamite hot potato/Thomas saves the construction site/Arguing with Sir Topham Hatt
- Sailor John steals the Treasure/The Chase
- Sir Topham Hatt apologizes/the grand opening/"We Make a Team Together"