Serving at 3-0, Soler-Espinosa hit a forehand and a backhand winner before Williams netted a down the line backhand to fall behind 0-4.
Down 0-4, Williams hit two crosscourt backhands long before double-faulting to drop serve
and trail 0-5 at which point the American had only won seven points for the day.
With the Spaniard serving for the set, Williams saved three set points; the third setpoint erased with a Williams crosscourt backhand winner to reach the second deuce of the game.
Williams broke serve to reach 1-5 following two forehand errors from Soler-Espinosa.
However following a double fault and a netted backhand down the line, Williams faced a fourth setpoint which she erased with a crosscourt backhand winner before holding serve to reach 2-5.
Hitting harder and without a considerably lower number of errors, Williams powered to a 7-5 one set lead.
Serving to open set two, Williams blasted three aces down the tee before holding serve to lead 1-0 after winning a total of eight games in a row.
The American broke serve at 2-1 before holding serve later in the set to reach 5-2.
Serving down 0-40, the Spaniard saved two match points before netting an inside out forehand down the line to end the match after one hour and 14 minutes of play.
Williams finished the match with 27 winners including nine aces.
Later this week Williams could play her close friend, the 6th seeded Caroline Wozniacki of Denmark in the quarterfinals in a rematch of the US Open final.
In the semifinals, Williams could play her sister, the 16th seeded Venus Williams.
Of her slow start Williams said after the match, “I didn't want to lose 6-0. I just started fighting. I was like, just let me at least try to break here. I just started hitting a couple days ago, taking it day by day. Finally I decided I'm here, I may as well see what happens. I'm feeling a lot better. I have more energy.”