I was very surprised on our recent Seabourn Legend cruise along the Mex Riv, when we were asked to report to immigration on a sea day. US Immigration officer was on the ship. I assumed they boarded in Cabo, our last port before a US port.
I'd never seen this before. In the Caribb, Immigration procedure has always been in the morning of debarkation, once the ship is in the home port.
You won't have to worry in Europe though. Last fall we were on a Celebrity cruise there, and the cruise line did not even keep our passports.