He got the last laugh.

Loved ones at an Irish funeral for Defense Forces veteran Shay Bradley were shocked — then delighted — when they heard the voice of their late friend calling out from his coffin.

“Hello, hello — let me out!,” they heard on Saturday at Bradley’s funeral in Kilmanagh, Leinster, as his casket was lowered into the ground.

The pre-recorded message continued, “Where the f - - k am I? Let me out, let me out. It’s f - - king dark in here. Is that the priest I can hear? This is Shay, I’m in the box. No, in f - - king front of you. I’m dead.”

A video of the posthumous prank, posted to Twitter Sunday, shows mourners laughing and crying as Bradley’s voice began to sing, “Hello again, hello. Hello, I just called to say goodbye.”

The footage has gone viral with more than 500,000 views and over 16,000 likes.

Friends and family said the good-humored officer and father made the recording because he knew he was dying of a “long illness bravely borne” — and wanted “to make his family laugh rather than cry at the funeral.”

Those close to him are now using the hashtag “#shayslastlaugh” to share the story.

“My dad’s dieing [sic] wish, always the pranksters,” wrote his daughter Andrea on Facebook, in a post with more than 70,000 views. “Ya got them good Poppabear 😉 and gave us all a laugh just when we needed it!! I will love you forever 😘😘#shayslastlaugh.”

She added on Twitter, “What a man . . . To make us all laugh when we were incredibly sad . . . He was some man for one man . . . Love you forever Poppabear #Shayslastlaugh.”

Other veterans of the Defense Force said the video of their colleague’s funeral “says it all” about military humor.

“Was asked a question the other day, it was what’s the difference between military humour and Civilian humour it’s simple it’s black. This video should say it all,” they posted on Facebook.

Bradley, who died Oct. 8, is survived by his wife, Anne, and children, Jonathan, Susanne, James and Andrea.