Halep needed to reach the quarter-finals and progress further than No. 2 Caroline Wozniacki to hold onto the top spot, and she accomplished the first task.
Wozniacki was facing 15th-seeded Anastasija Sevastova in a late match on the red clay of the Foro Italico. The winner will play Anett Kontaveit.
Keys also withdrew from the doubles competition, where she was partnered with Williams.
Last year in Rome, Halep rolled her ankle in the final and lost a lead and the championship to Elina Svitolina.
Halep will next play either U.S. Open champion Sloane Stephens or seventh-seeded Caroline Garcia.
Svitolina also reached the quarter-finals, overcoming a poor start to beat 14th-seeded Daria Kasatkina 0-6, 6-3, 6-2. She’ll next face former No. 1 Angelique Kerber, who routed Maria Sakkari of Greece 6-1, 6-1.
This is the last major warm-up for the French Open, which starts in 10 days.
Jelena Ostapenko, who is preparing to defend her title at Roland Garros, rallied past Johanna Konta 2-6, 6-3, 6-4 and will meet either three-time Rome champion Maria Sharapova or Daria Gavrilova.