Top seed Sharapova, the 2004 champion, had to dig deep to clinch a gritty 7-6 (7/3), 6-7 (3/7), 6-0 victory over Bulgaria's Tsvetana Pironkova, a semi-finalist in 2010 and quarter-finalist last year.
Sharapova, playing her first tournament since her maiden French Open triumph, had recovered from 5-2 down to take the first set and had just broken to move 3-1 ahead when the tie was suspended due to bad light on Wednesday evening.
On the resumption, Pironkova belied her ranking of 38 to level the tie as the Court One crowd sensed an upset.
It was the first set the 24-year-old had snatched from the Russian in four meetings, but Sharapova took her 2012 three-set record to a perfect nine from nine by racing through the decider.
She will next face Taiwan's Hsieh Su-Wei as last year's runner-up tries to reach the Wimbledon final for the third time.
"I started so slow today, but I guess it's more important how you finish," said Sharapova after sweating for over two hours.
"She loves playing on grass and came out firing. I was a bit tentative and just couldn't get much rhythm.
"But I tried to focus on my game and I'm happy I really stepped it up in that third set."
Four-time champion Williams reached the third round with a 6-1, 6-4 demolition of Hungarian qualifier Melinda Czink.
Sixth seed Williams faces Chinese 25th seed Zheng Jie, who she beat in the 2008 semi-finals, for a place in the last 16.
"As the tournament goes on, you tend to play a little better," said Williams, who fired 10 aces, hit 22 winners and conceded just seven points on her own serve in her 61-minute win.
"It was great to be back on Centre Court. It's amazing and I served really well."
Kei Nishikori, the 19th seed, became the first Japanese man to reach the third round for 17 years by beating France's Florent Serra 6-3, 7-5, 6-2.
Nishikori had already made history earlier this year when he became the first Japanese man to reach the Australian Open quarter-finals in 80 years.
Now the 22-year-old has emulated Shuzo Matsuoka's Wimbledon run to the last 32 back in 1995. Matsuoka went on to reach the quarter-finals where he lost to Pete Sampras.
Japanese tennis could receive another welcome boost later on Thursday if Go Soeda can shock former US Open champion Juan Martin del Potro.
That would put two Japanese men in the third round for the first time since 1937 and set up an all-Japan last 32 clash between Nishikori and Soeda.
Later Thursday, world number two Rafaal Nadal, the champion in 2008 and 2010, takes on Lukas Rosol for a place in the last 16 while fourth-seeded Briton Andy Murray faces giant Croat Ivo Karlovic.
The Scot has won all three of his previous meetings with Karlovic.
French fifth seed Jo-Wilfried Tsonga, who reached the semi-finals after knocking out Roger Federer last year, plays Spain's Guillermo Garcia-Lopez, with three-time runner-up Andy Roddick facing unseeded German Bjorn Phau.
Women's defending champion Petra Kvitova, the fourth seed, meets Britain's Elena Blatacha.Wimbledon results.
(For more sports news and updates, follow Ahram Online Sports on Twitter: @AO Sports / and Facebook AhramOnlineSports)