Backwards Timeline for the Trial of Socrates:
~389 BC Plato writes the Apology
399 trial and execution of Socrates
403 General amnesty declared for crimes committed during the Tyranny
403 Overthrow of the Thirty Tyrants
404 The Thirty Tyrants come to power
404 Final surrender of Athens to Sparta ends the Peloponnesian War
405 Obliteration of the Athenian fleet in Battle of Aegospotami
415 Massive Athenian naval expedition to Sicily ends in disaster
415 Desecration of the Herms
~417 Aristophanes' The Clouds
421 Peace of Nicias
422 Battle of Amphipolis
424 Battle of Delium
431 Beginning of Peloponnesian War
432 Battle of Potidaea
The trial and execution of Socrates came during the tumultuous years following the collapse of the Athenian Empire. In 405 BC the Spartans destroyed nearly the entire Athenian fleet and the following year the decades-long Peloponnesian War between the two most powerful Greek city-states came to an end with the surrender of Athens. This was followed by the imposition of a new government in Athens, comprised of men hand-picked by the Spartans, the so-called Thirty Tyrants. Under this regime many Athenians were forced into exile, and hundreds were condemned to death. A state of civil war ensued, and soon the Thirty Tyrants were in turn overthrown in 403 and replaced by a new government controlled by a resurgent "democratic party" made up largely of recent exiles under the leadership of Thrasybulus. Although a general amnesty was declared, Socrates' powerful enemies were able to whip up popular sentiment against their nemesis by making him a scapegoat for Athens' ruinous reversal or fortune. According to Diogenes Laertius Socrates was "the first philosopher who was tried and put to death." After the execution, also according to Diogenes Laertius, "the Athenians immediately repented of their action", and all those who had been behind bringing Socrates to trial were themselves either sent into exile or put to death.
Unfortunately, some people have the mistaken impression that Socrates was some kind of semi-legendary figure who might not have even existed at all. In fact, Socrates is one of the most well-documented persons in all of ancient history. Take his execution, for example. Plato lists 12 people by name who were all present with Socrates when he drank the hemlock in his prison cell (Plato himself was not there). These are all historically attested persons who really were Socrates' students, and at least six of them wrote surviving (if only in fragments) philosophical dialogues recounting Socrates' teachings. In addition we have the far more extensive writings of two of Socrates' more famous students who were not there when he was executed: Xenophon and Plato.
We know the names of Socrates' father and mother (Sophroniscus and Phaenarete) and even their probable professions (stone-cutter and midwife, respectively), the names of his children (Lamprocles, Sophroniscus and Menexenus), and we also know the name of one of his wives (Xanthippe), and possibly of another one (Myrto), although sources differ on the number and order of Socrates' marriages. We do not know for certain the year of his birth but there is no doubt that he died in the year 399 BC.
Concerning the trial itself, in his The School of History Mark Munn writes that
The indictment of Socrates is well attested in several contemporary paraphrases, and is reliably quoted by Diogenes Laertius, at second hand, from a work by Favorinus of Arelate, a sophist of the early second century CE who consulted the text of the indictment still preserved in the official archives of the Metroon at Athens. It reads as follows:Plato's Apology, which recounts Socrates' trial, was written within a decade of the trial itself, therefore many of those who read it when it first appeared had been alive at the time or were even present at the trial (as Plato tells us he was). R.E. Allen's assessment of the historicity of Plato's Apology is, in part, as follows:
Meletus son of Meletus of Pitthus has written a sworn indictment against Socrates son of Sophroniscus of Alopece as follows: Socrates commits the offense of not acknowledging the Gods acknowledged by the state and of introducing other new divinities. He commits the further offense of corrupting the young. Penalty proposed: capital punishment.
Plato's Apology purports to represent a historical occurrence, namely, the speech which the historical Socrates made at his trial. It is a natural question, and one often asked, whether Plato's representation of that speech is historically accurate.In his defense speech, Socrates states that he must counter two types of enmity against him. First there is the long-standing hatred of him among many of his fellow Athenians, and second there are the specific charges brought against him by three citizens, Anytus, Meletus, and Lycon. Although Socrates does not say so explicitly, the specific charges against him were simply a means to and end, namely, The Elimination of Socrates, as Mark Munn titles the section of his book devoted specifically to the trial and execution of Athens' most famous citizen. Socrates does come pretty close to stating this, though, when he points out that one of the charges against him is that he had "introduced new Gods", while one of his accusers, Meletus, accuses Socrates (during the trial itself) of believing in no Gods whatsoever, with the clear implication being that the specifics of the charges are of little or no concern to the accusers, who simply want to exact vengeance against their enemy, Socrates, by any means necessary.
A kind of conventional wisdom has grown up as an answer. It claims that the Apology represents sheer idealization of the master's life, that it is a fiction. I believe that within such limits of proof as the subject matter admits, this answer is provably mistaken. As a matter of best evidence, the Apology should be admitted as essentially accurate to historical fact.
By saying that the Apology is essentially accurate I don't mean that it is a word-for-word presentation of Socrates' speech.... [T]here is good reason to suppose that the Apology is not a stenographic report, even though Plato takes pains to indicate that he was present and heard the speech (34a, 38b), something he does nowhere else in the dialogues.... [T]he Apology reproduces the general substance of what Socrates said and the way he said it....
There is no good evidence that the Apology is inaccurate. There is good evidence that the Apology is accurate.... This need hardly occasion surprise. Plato could have had no good reason for presenting an account of Socrates' defense which was at variance with the facts to an audience thoroughly familiar with what Socrates had actually said. This point, indeed, applies in general to the early dialogues. Given that Socrates cared deeply to know what piety and other virtues are, and knew that he did not know, his ignorance would have prevented him from denying the charges brought against him. It follows that Socrates could have made essentially the speech which Plato presents, and perhaps he could have made no other.[Allen 1984, pp. 76-78]
Just how dangerous these times were, and how poisonous the intellectual climate had become, is darkly foreshadowed by these words of Thucydides, writing about the factional conflicts that rocked the city of Corcyra near the beginning of the Peloponnesian War, almost three decades before Socrates drank the hemlock:
Words had to change their ordinary meaning and to take that which was now given them. Reckless audacity came to be considered the courage of a loyal ally; prudent hesitation, specious cowardice; moderation was held to be a cloak for unmanliness; ability to see all sides of a question inaptness to act on any. Frantic violence, became the attribute of manliness; cautious plotting, a justifiable means of self-defence. [3.82.4]
Further reading on the trial of Socrates:
The Dialogues of Plato, Volume 1 by R.E. Allen
The School of History: Athens in the Age of Socrates by Mark Munn
Free Speech and Democracy in Ancient Athens by Arlene W. Saxonhouse
Life of Socrates by Diogenes Laertius
Socratic Studies by Gregory Vlastos
Plato and the Socratic Dialogue by Charles Kahn
The Athenian Empire by Russell Mieggs
The History of the Peloponnesian War by Thucydides
Thucydides: An Introduction for the Common Reader by Perez Zagorin
The Athenians and Their Empire by Malcolm F. McGregor
Routledge Philosophy Guidebook to Plato and the Trial of Socrates by Tom Brickhouse and Nicholas Smith
Socrates in the Apology: An Essay on Plato's Apology of Socrates by CDC Reeve
The Unknown Socrates: Translations, With Introductions and Notes, of Four Important Documents in the Late Antique Reception of Socrates the Athenian [this is a realy fascinating book from Bolchazy, also check out the book's listing at Amazon, which let's you "look inside"]
[NOTE: I put a lot of wikipedia links in this post - but I checked them all out and they seem pretty good. There is, however, a specific wikipedia entry on "The Trial of Socrates" which is mind-bogglingly evil (and I am not providing a link to it - but it's easily found for those who have an interest in evil-ology). It sounds like it was written by some people whose only regret is that Socrates isn't alive today so that they could kill him all over again. The wikipedia entry for Socrates, though, is reasonably good, by wikipedia standards.]
The Varieties of Sceptical Thought:
 Sceptical Scepticism
 Socrates on Death
 Socrates' Advice to the Jury
 Richard Popkin
 Overview of the Trial of Socrates
 "Socrates of all mortals is the wisest"