Allen pulled a frame back but Cao took two more to go with one frame of victory with a tremendous 113 break.
The Northern Irishman was digging deep though, and responded with a century of his own, a 101 and the fightback was on.
Cao looked certain to win the 16th, but broke down giving Allen the chance to win the frame.
Gould hits 136 break against Gilbert
But the match ended in bizarre fashion, as Allen cleared up, only to see the cueball roll agonisingly into the corner pocket, handing Cao his victory on debut.
Earlier on in the day, 30-year-old
caused a surprise by beating fellow Englishman Martin Gould 10-8 to win his first match at the Crucible.
Gilbert, a former potato farmer, has made only one previous appearance in the final stages which ended in a 10-7 defeat by Stephen Hendry in 2007.
"It's a massive relief to get through. To have got over the line is great, and hopefully a few of the Tamworth massive might come up and cheer for me in the next round," he said after holding off a spirited Gould fightback.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.