By fortunate chance.
From Shakespeare's The Merry Wives of Windsor, 1600:
You shall hear. As good luck would have it, comes
in one Mistress Page; gives intelligence of Ford's
approach; and, in her invention and Ford's wife's
distraction, they conveyed me into a buck-basket.
Above retrieved from, http://www.phrases.org.uk/meanings/40700.html