BOSTON – Darnell McDonald spent the day in Boston, hanging out just in case he was needed. A few hours later, he saved the Red Sox from another embarrassing loss.

McDonald, called up from the minors earlier in the day, hit a pinch-hit two-run homer in the eighth inning to tie the game and won it with an RBI single in the ninth to lift the struggling Red Sox to a 7-6 comeback win over the Texas Rangers on Tuesday night.

“I don’t care how we did it. We desperately needed to win a game,” Boston Manager Terry Francona said. “We hung in there and won a game that we definitely needed to win.”

The Red Sox snapped a five-game losing streak despite allowing the Rangers to steal a team-record nine bases. Texas has dropped five straight.

McDonald, 31, signed as a minor-league free agent on Nov. 24, finished last season with Cincinnati and was a non-roster invitee to the Red Sox camp.

“I couldn’t write a script any better than this,” he said. “A lot happened. A dream come true. That’s why I signed over here to be able to play in this type of atmosphere.”

He was the first Red Sox player to homer in his initial plate appearance since Orlando Cabrera did it on Aug. 1, 2004, at Minnesota.

Kevin Youkilis opened the ninth with an infield hit off the body of Frank Francisco (2-3), advanced on a passed ball and was sacrificed to third by Bill Hall. After Mike Lowell was intentionally walked and Adrian Beltre popped to first, Jason Varitek then walked on four pitches before McDonald lifted a fly ball that scrapped the Green Monster just over the leap of Josh Hamilton.

McDonald was mobbed in short left field as the Rangers trotted off the field.

“They got me pretty good out there,” he said, still beaming.

Nelson Cruz and Elvis Andrus each stole three bases as the Rangers opened a 6-1 lead after five innings.

“We didn’t figure out a way to shut the game down,” Rangers Manager Ron Washington said.

Jonathan Papelbon (1-1) pitched a hitless ninth for the win.

The Rangers stole all nine against knuckleballer Tim Wakefield and catcher Victor Martinez.

“I was just concentrating on throwing strikes and wasn’t keeping an eye on the running game, which showed — they stole nine bases off me,” Wakefield said. “I know it’ll get better.”

Josh Reddick, also recalled Tuesday from Triple-A Pawtucket, had a two-run double for Boston, cutting the deficit to 6-4 in the sixth.

The Rangers were 18 for 18 in stolen-base attempts against the Red Sox last season. The previous team record was eight, set against Boston at Arlington, Texas, last Aug. 15.

Cruz started the Rangers’ running game in the first when he had an RBI single to make it 1-0 and followed by stealing second.

Martinez’s RBI single in the bottom of the inning tied the game. Boston had gone 0 for its last 32 with runners in scoring position.

Texas set a club record for steals in an inning with five in the third. Hamilton’s grounder scored Andrus to make it 2-1. Andrus walked leading off, then stole second and third. Vladimir Guerrero stole two bases and Cruz the other in the inning.