Back to the Future Part III

On November 12, 1955, Marty McFly discovers that his friend, Dr. Emmett Brown is now trapped in 1885. Marty and Doc's 1955 self use the information in Doc's 1885 letter to locate and repair the DeLorean. Marty 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.
Marty arrives on September 2, 1885, in the middle of a United States Cavalry pursuit of Indians. When the fuel line is torn, Marty hides the car in a cave and walks 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 commercial gasoline is not yet available, the DeLorean cannot reach 88 miles per hour under its own power.
Doc devises a plan to use a locomotive to push the DeLorean up to the required speed. While he and Marty explore a rail spur they intend to use, they spot an out-of-control horse-drawn wagon. Doc saves the passenger, Clara Clayton, and the two fall in love. Marty thwarts Buford's attempt to kill Doc at a town festival, whereupon Buford challenges Marty to a showdown in two days. Doc's name disappears from the photograph of his tombstone, but the date remains unchanged; Doc warns Marty that he might be the one 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, and is then arrested for an earlier robbery. Marty and Doc depart to steal the locomotive.
As Clara is leaving on the train, she overhears a salesman discussing how heartbroken Doc was at the saloon. Clara applies the emergency brake and runs back to town. She discovers Doc's model of the time machine and rides after him. Having stolen the train at gunpoint, Doc and Marty 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 his 2015-era hoverboard to Doc so he can save Clara. They coast away from the train as the DeLorean returns 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 Douglas J. Needles, avoiding a possible automobile accident. Remembering that this accident would have sent Marty's life spiraling downward by 2015, Jennifer opens a fax message she kept from 2015 and watches as its text regarding Marty's firing disappears.
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.

Question: In which year did Doc agree to leave?
Answer: 1885; 1885