The Wimbledon and Olympic champion, an overwhelming favourite for the title, needed 82 minutes to dig out a 6-2 6-4 victory over 30-year-old Martinez Sanchez.
Serena started superbly, winning 12 straight points as she led 4-1 but struggled thereafter, double-faulting six times and making a slew of simple mistakes.
Martinez Sanchez could not capitalise, squandering a 2-0 lead in the second set as Serena battled through to face Ekaterina Makerova, who beat fellow Russian Elena Vesnina 6-3 6-4 .
"It was one of those days," Williams said. "I wasn't really happy with the way I was playing. I just wasn't happy out there today in general. I think I woke up on the wrong side of the bed."
Serena hurt her ankle on Wednesday while playing doubles with her sister Venus but it appeared to have little effect on her play against Martinez Sanchez.
She first hurt the ankle at the Australian Open in January.
"I was running for a shot and rolled it," said the 30-year-old American, seeking her fourth US Open crown. "Story of my ankle life. But it was fine. I did a lot of ice and (elastic) tape, compression to keep the swelling out.
"I rolled it in Australia so I was a little nervous but it's fine."
Serena blasted 32 winners but had an uncharacteristic 24 unforced errors in the one hour, 22-minute match on Arthur Ashe Stadium.
Both Serena and Martinez Sanchez had seven break-point opportunities but while Williams was successful on four, the Spaniard could convert only on one.
Germany's sixth seed Angelique Kerber survived a tense battle against Venus Williams 6-2 5-7 7-5 in a late-finishing match on Arthur Ashe Stadium court.
The first five games of the match were all service breaks before Kerber, a semi-finalist at Flushing Meadows a year ago, began to dominate.
The unseeded Venus staged a revival to lead 4-2 in the third set but Kerber prevailed to meet Olga Govortsova from Belarus in the third round. Govortsova beat Britain's Johanna Konta 2-6 6-2 7-5.
Venus, a two-times US Open champion, made 60 unforced errors in an erratic performance.
Former world number one Ana Ivanovic cruised into the third round with a 6-2 6-2 victory over Swede Sofia Arvidsson under sunny skies in Arthur Ashe Stadium.
The 13th seeded Ivanovic, who broke Arvidsson's serve six times, needed only 64 minutes to advance while defeating her 28-year-old rival for the fourth time in five career meetings.
In the third round, Ivanovic will face American Sloane Stephens, who saw off German qualifier Tatjana Malek 5-7 6-4 6-2.
Ivanovic enjoyed a 39-7 advantage in winners, as Arvidsson's groundstrokes did little to offset the arsenal of her 24-year-old Serbian opponent trying to advance to the quarter-finals for the first time at Flushing Meadows.
Second seed Agnieszka Radwanska won 11 straight games as she recovered to beat Carla Suarez Navarro of Spain 4-6 6-3 6-0 in a second-round battle.
The Wimbledon runner-up looked in trouble when world number 39 Suarez Navarro was leading 3-1 in the second set but Radwanska hit back to claim victory after one hour, 57 minutes.
In a gruelling match containing a series of long rallies, Suarez Navarro took the attack to Radwanska and the Pole in trouble for a set and a half.
But when she broke back for 3-3, everything changed and she reeled off the next nine games to set up a meeting with former world number one Jelena Jankovic of Serbia. Jankovic booked her place in the third round with a 6-4 6-2 win over Spain's Lara Arruabarrena Vecino.
Fourteenth seed Maria Kirilenko continued her good form with a regulation 6-3 6-2 win over Greta Arn to book a date with Andrea Hlavackova, the Czech having beaten Galina Voskoboeva of Kazakhstan 6-2 6-7(3) 6-3.
Number 10 seed Sara Errani was in blistering form as the Italian crushed Vera Dushevina 6-0 6-1 to set up a clash with Olga Puchkova, who progressed past Kiki Bertens 5-7 6-2 7-5.
Another Italian, Roberta Vinci, also won through, the 20th seed beating Kazah Yaroslava Shvedova 3-6 7-5 7-5. She goes on to meet Dominika Cibulkova, the 13th seed from Slovakia who beat Serbia's Bojana Jovanovski 7-6(3) 7-6(3).
Completing the third round draw are Silvia Soler Espinosa and Tsvetana Pironkova, who progressed with respective 6-4 7-6(5) and 7-5 6-2 victories over Irina Begu and Ayumi Morita.
- Venus Williams