The Sherlock star, 37, was sat in the front row as Judi was being interviewed by director Richard Eyre as part of a Shakespeare masterclass on the final day of the festival.
During the Q&A section, he seized his opportunity, and asked if she would appear in the play with him. "Yeah!" she replied to cheers from the crowd.
Benedict Cumberbatch ambushed Dame Judi Dench when she was doing a Q&A at the Hay Festival
Benedict, who will star as the hunchback king in the new BBC production, had reportedly been pursuing Judi, 79, to play Queen Margaret for months.
Immediately after the Q&A session, Benedict joined Dame Judi on stage to perform short excerpts from plays, including Anthony and Cleopatra and Twelfth Night.
Richard III will be directed by Dominic Cooke, and is the concluding part of The Hollow Crown, a series of Shakepeare history plays for the BBC which began in 2012.
Benedict Cumberbatch is well known for playing the title role in the series Sherlock
Meanwhile, Benedict is also being tipped for a lead role in a proposed movie based on RC Sherriff’s Journey’s End.
The star is being considered to play hero Captain Stanhope in the film about a group of officers fighting in the trenches, the Sunday Times reports.
Other British actors tipped for a part in the war drama including Tom Hiddleston and Eddie Redmayne.