mid-14c., "by chance or accident;" late 14c., "by good fortune, luckily," from happy + -ly (2). Sense of "in pleasant circumstances, with mental pleasure and contentment" is from 1510s. Happily ever after recorded by 1825.
they shouted happily
happily he was not injured