In dubio pro reo

The principle of in dubio pro reo (Latin for "[when] in doubt, rule for the accused") means that a defendant may not be convicted by the court when doubts about their guilt remain.

The rule of lenity is the doctrine that ambiguity should be resolved in favour of the more lenient punishment.

To resolve all doubts in favour of the accused is in consonance with the principle of presumption of innocence.

Origin
The main principle in the sentence was part of Aristotle's interpretation of the law and shaped the Roman law: Favorabiliores rei potius quam actores habentur (Digest of Justinian I, D.50.17.125), meaning "The condition of the defendant is to be favored rather than that of the plaintiff." However, the phrase was not spelled out word for word until the Milanese jurist Egidio Bossi (1487–1546) related it in his treatises.

National peculiarities
In German law, the principle is not codified but has constitutional status and is derived from Article 103(2) of the Basic Law, Article 6 of the ECHR, and Section 261 of the Code of Criminal Procedure. The common use of the phrase in the German legal tradition was documented in 1631 by Friedrich Spee von Langenfeld.

In Canadian law, the leading case establishing how to decide criminal cases where the guilt of the accused depends on contradictory witness accounts is R. v. W.(D.) (1991).