In certain cases, attorneys can move for a mistrial. A motion for mistrial is simply asking the court to end the trial sometime after jeopardy attaches (in a jury trial, after the jury was sworn; in a court case, after the first witness is sworn) but before the verdict was returned.
If an error was committed during the trial that would so prejudice the jury or judge (in a bench trial) that a curative jury instruction would not help, the motion should be granted. Examples of incurable prejudice are mistakenly allowing prejudicial evidence to be admitted, substitution of counsel mid-trial, jury misconduct, jury deadlock, jury losing too many members due to illness or other reason beyond the court’s control, etc. The commonly referred to "hung jury" is simply a type of mistrial in which the jury is unable to reach a verdict.
If the defense did not make the motion for a mistrial and the defense does not say that it agrees with the court’s decision to order a mistrial, jeopardy attaches and the defendant cannot be retried for the same offense. Unfortunately, it is often the defense who moves for a mistrial, allowing for the retrial of the case in most instances.