Charles, Benedict Cumberbatch and David Tennant lit up social media during Shakespeare Live!

Updated: 

The Prince of Wales made a surprise appearance as Hamlet in the star-studded Shakespeare Live! on BBC Two, filmed in the Bard's birthplace in Stratford-upon-Avon.

He shared the stage for a funny skit about Hamlet with renowned actors including Dame Judi Dench, Sir Ian McKellen, Benedict Cumberbatch and David Tennant.

Charles on stage with the Shakespeare Live! cast
Charles on stage with the Shakespeare Live! cast (BBC)

Comedian Tim Minchin also added some mirth and Dame Judi had one of the wittiest lines: "It is I, Hamlet the Dame!" she declared.

There was also a running gag about Eddie Redmayne with Sir Ian saying to Benedict: "Eddie Redmayne! I loved you in The Danish Girl!"

Dame Judi Dench with David Tennant
Dame Judi Dench with David Tennant (BBC)

Charles, who had been watching the Shakespeare Live! from The Royal Shakespeare Company show with the Duchess of Cornwall, was heard to speak from the wings, asking: "Might I have a word ... "

Then followed the opening lines to what is one of Shakespeare's best-known soliloquys: "To be or not to be, that is the question."

Sir Ian McKellen joins in the fun
Sir Ian McKellen joins in the fun (BBC)

Fans watching could scarcely believe their eyes and many posted their thoughts on Twitter.

Charles rocked!

Best. Sketch. Ever.