The world number one was trailing 5-2 in the opening set against Li Na, but won five straight games to eventually take the set 7-5.
Williams found the second set more straightforward, taking it 6-1 to see off the world number two.
"It was a really important victory, especially playing Li Na, who has been playing so well," Williams is quoted as saying by CNN.
"She started out so well. I was like, 'Oh my gosh, I just need to hang in here.' Then I heard some fans trying to pull me through. If it hadn't been for you guys I wouldn't be standing here right now."
Williams lifted her seventh Miami Masters title with the straight-sets victory.