The Italian French Open finalist had previously not won a match at Wimbledon.
World number 13 and former US Open finalist Keys, 29, had been 3-6 7-6 (8) 5-2 up on Paolini when the American pulled her left hamstring.
“It’s bad to end the match like that, I’m a little bit happy but sad for her, it’s hard to win like that,” said the Lucca-born 28-year-old.
“I love this (centre) court and I hope I’ve become a crowd favourite, thanks to all the Italians who are here, grazie ragazzi”.
Paolini will face reigning US Open champion and second seed Coco Gauff or American 19th seed Emma Navarro for a place in the semi-finals.
ANSA