On November 12, 1955, Marty McFly discovers that his friend, Dr. Emmett “Doc” Brown, had become trapped in 1885. Marty, with the 1955 Doc, uses the information in Doc’s 1885 letter to locate and repair the DeLorean. He spots a tombstone with Doc’s name, dated six days after the letter. Learning that Doc was killed by Biff Tannen’s great-grandfather, Buford “Mad Dog” Tannen, Marty travels back to 1885 to save Doc.
Having arrived on September 2, 1885, in the middle of a United States Cavalry pursuit of Indians, the DeLorean’s fuel line is torn, forcing Marty to hide the car in a cave and walk to Hill Valley. He meets his Irish-born great-great-grandparents, Seamus and Maggie McFly, and runs afoul of Buford and his gang. Buford tries to hang Marty, but Doc saves him. Doc agrees to leave 1885, but because the DeLorean is out of gasoline, they are unable to accelerate the DeLorean to 88 miles per hour.
Doc devises a scheme to use a locomotive to push the DeLorean up to speed. Doc and Marty explore the rail spur they intend to use and spot an out-of-control horse-drawn wagon. Doc saves the passenger, Clara Clayton, and the two fall in love. Buford tries to kill Doc at a town festival, but Marty saves him. Buford goads Marty into a showdown in two days’ time. In the photograph of Doc’s tombstone, Doc’s name has disappeared, but the date on the tombstone remains unchanged. Doc warns that Marty might be killed by Buford.
The night before their departure, Marty and Doc place the DeLorean onto the rail spur. At Clara’s house, Doc tells her he is from the future, but she believes it is an excuse to end their relationship and angrily dismisses him. Distraught, Doc returns to the town saloon for a binge, but Marty rides to the saloon and convinces Doc to leave with him. Doc drinks a single shot of whiskey and passes out instantly. Buford arrives early and calls out Marty, but Marty refuses to duel. Doc revives after drinking the bartender’s special “Wake-Up Juice” and tries fleeing with Marty, but Buford’s gang captures Doc, forcing Marty to duel. During a fistfight, Buford destroys the tombstone, is knocked unconscious into a wagon full of manure, then arrested for an earlier robbery. Marty and Doc depart to “borrow” the locomotive.
As Clara is leaving on the train, she overhears a salesman discussing a man he met in the saloon, despondent about his recent breakup. Realizing the man is Doc, Clara applies the emergency brake and runs back to town. She discovers Doc’s model of the time machine and rides after him. Doc and Marty, having stolen the train at gunpoint, begin pushing the DeLorean along the spur line, attempting to get it up to 88 miles per hour. Clara boards the locomotive while Doc climbs towards the DeLorean. Doc encourages Clara to join him. As she climbs to Doc, Clara falls and hangs by her dress. Marty passes the hoverboard to Doc, who saves Clara. They coast away from the train as the DeLorean disappears to 1985, while the locomotive falls off the unfinished bridge.
Marty arrives on October 27, 1985, escaping the powerless DeLorean before it is destroyed by an oncoming freight train. He discovers that everything has returned to the improved timeline and finds Jennifer sleeping on her front porch. He uses the lessons he learned in 1885 to avoid being goaded into a street race with Needles, avoiding an automobile accident. Jennifer opens the fax message she kept from 2015 and watches as the message regarding Marty being fired is erased.
Marty takes Jennifer to the time machine wreckage. A locomotive equipped with a flux capacitor appears, manned by Doc, Clara, and their two children Jules and Verne. Doc gives Marty a photo of the two of them by the clockworks at the 1885 festival. Jennifer asks about the fax, and Doc tells them it means that the future has not been written yet. Doc’s train converts into an aerial craft and disappears into an unknown time.