As criminal courts become ever more crowded, prosecutors and judges feel increased pressure to move cases quickly through the system. Trials can take days, weeks or sometimes months while guilty pleas can often be arranged in minutes. Also, the outcome of any given trial is usually unpredictable -- but a plea bargain provides both prosecution and defense with some control over the result.
In theory, a plea bargain may be negotiated at any time after arrest. In practice, however, the time to plead depends on the court and the jurisdiction -- some jurisdictions allow plea bargains only during certain phases of the criminal process. In many other places, however, plea bargains can be worked out virtually any time -- from shortly after the defendant is arrested (before the prosecutor files criminal charges) up to the time a verdict is reached -- even during trial itself. Also, if the trial results in a hung jury (the jurors are split and cannot make the unanimous decision required), the prosecution and defense may (and often do) negotiate a plea rather than go through yet another trial.