The comedian, 42, barged into Murray’s hotel room as the twice Wimbledon tennis champion slept soundly.
A shirtless Murray, 30, then sat up in bed to play Midnight Gameshow, for a sketch to air on BBC1.
Murray’s family and team helped prepare the stunt.
The tennis star, who is continuing his comeback from injury, said: “When I went to sleep, Michael McIntyre was the last person I expected to see at the foot of my bed in the middle of the night.
“Once I got over the initial shock and managed to wake up, I had fun and it is great that it will help to raise money for such a good cause.”
McIntyre said: “The minute the idea was mentioned I knew we had to make this happen....
“Thankfully Andy saw the funny side and he was a great sport throughout. I can’t wait for everyone to see it.”
Sport Relief 2018 will be broadcast live on March 23 on BBC1, with presenters Freddie Flintoff, Gary Lineker, Davina McCall, Paddy McGuinness, Ore Oduba and Claudia Winkleman.
Money raised through the charity helps vulnerable people in the UK and across the world.