Chief Medical Officer Leonard McCoy (DeForest Kelley) is treating an injured Lt. Hikaru Sulu (George Takei) when the Enterprise is rocked by a distortion, and McCoy accidentally injects himself with an overdose of cordrazine. Delusional, he flees from the bridge to the transporter room, beaming himself down to a nearby planet. Captain James T. Kirk (William Shatner) leads a landing party to look for McCoy, and they come across an ancient glowing stone ring, which is causing time distortions.
The Guardian of Forever (voiced by Bartell LaRue) explains that it is a doorway to any time and place.
While Spock (Leonard Nimoy) is recording historic images from the portal, McCoy escapes through it, into the past. The landing party suddenly loses contact with the Enterprise and is informed by the Guardian that the past has been altered. The shipalong with the entire Federationno longer exists.
The Guardian permits Kirk and Spock to follow McCoy in an effort to repair the timeline. They arrive in New York City during the 1930s Great Depression. After stealing some clothes in order to blend in, they meet a woman named Edith Keeler (Joan Collins), who runs the 21st Street Mission. Spock begins to construct a processor to interface with his tricorder to find out how McCoy altered history. He discovers that they arrived at some point shortly before McCoys arrival. While they await his arrival, they work for Keeler and Kirk begins to fall in love with her. After some time, unbeknownst to Kirk, McCoy stumbles into the mission, delirious, and Keeler takes him in. Spock finishes his work reviewing the Guardians images of the original and altered timelines and discovers Keeler was supposed to have died in an accident, which was prevented by McCoy. Instead, Keeler started a pacifist movement, causing the United States to delay its entrance into World War II, allowing Nazi Germany enough time to develop a nuclear weapon and win the war. Kirk knows that Keeler must be allowed to die in order to undo the damage to the timeline. (blah, blah, blah)...
https://en.wikipedia.org/wiki/The_City_on_the_Edge_of_Forever#Plot
"He knows, doctor, he knows."