Massage is able to help with sleep in the same way that it helps with stress. It helps with the production of the feel good chemicals that help you to feel calm and relaxed.
Also, if pain is keeping you awake then a massage to address the pain will also go a long way towards helping you to sleep.