Pain is certainly challenging for sleep. Trying to alleviate as much pain as possible prior to sleep, meaning taking whatever pain medication you are using well in advance of bedtime, utilizing sustained release meds where possible (so they last through the night)and recognizing it may be more difficult than usual can all be helpful.
Another approach might be to meditate, or use a guided meditation in bed instead of trying to sleep. Supporting deep relaxation can allow sleep to emerge whereas “trying” to sleep can have a paradoxical agitating affect.