Martinez's two-out hit gave the Red Sox a 5-4 lead and the win in the opener of the three-game series put them 1½ games ahead of the Rangers.
Boston tagged Texas closer Frank Francisco (2-2) for seven hits and six runs before he was pulled after a two-run home run by J.D. Drew.
Michael Young had a two-run homer and three RBIs for the Rangers.
Andrew Jones had a go-ahead single in the sixth inning for Texas after David Ortiz wiped out a 2-0 Texas lead with a two-run homer in the top of the inning.
The Rangers came within a strike of winning after pinch-runner Clay Buchholz was thrown out at home plate as the tying run on a double by Dustin Pedroia.
Buchholz, a starting pitcher, hesitated when Texas left fielder David Murphy leaped to try to catch Pedroia's drive at the wall. Murphy quickly retrieved the ball and threw to Young, whose relay got a sliding Buchholz. The Red Sox ended up with runners at second and third, and Martinez followed with the go-ahead hit.
Red Sox reliever Takashi Saito (3-3) got the win after pitching a scoreless eight inning. Jonathan Papelbon finished in a non-save situation.