The Guardian of Forever is a powerful entity that described itself as both and neither machine or being. Its function was as a time portal, which Captain James T. Kirk discovered when a drugged and hysterical Dr. McCoy leapt through the Guardian's portal, traveling back to 1930s Earth, and thus altering the timeline such that the Enterprise ceased to exist. Kirk and Mr. Spock therefore followed McCoy back in time to correct what McCoy altered.
Little is known about the Guardian of Forever. The Guardian served as a conduit for a race which traveled to a new age, thus leaving the planet – loosely referred to as the "Time Planet? – with the Guardian as its only indigenous, sentient resident. The Guardian is more than ten million years old. Its function seems to be that of showing the past of any planet, with the exception of the Time Planet itself, and of allowing journeys in time.
Not much is known about the civilization which built the Guardian, other than impressive, extensive ruins and the Guardian of Forever itself. The materials and principles on which the Guardian of Forever are based upon are completely unknown.
The Guardian, which is able to communicate, urged Kirk and his away team to serve as their gateway to any place, any time. But following the events Kirk endured during his experience, namely the death of Edith Keeler, Kirk was more than eager to return to his ship once the timeline was corrected.
A couple of years later (2269), the Enterprise crew did return to the Guardian of Forever to assist a team of historians in the investigation of Federation history. While Kirk, Spock and a historian were on a trip to the dawn of Orion civilization, other researchers used the Guardian to scan recent Vulcan history. This caused an alteration in the timeline in which Spock died as a child, and thus never became first officer of the Enterprise; Spock's mother also died prematurely in this altered chronology. Spock re-entered the Guardian to travel 30 years back to his home on Vulcan, in order to re-enact a paradox in which he saved himself from being killed by a wild animal, thus restoring the familiar time plane.