New York won despite stranding 14 runners in the first eight innings, blowing a 7-4 lead and making two errors in a five-run eighth.
Posada's two-run homer in the eighth tied the game for the Yankees, who then won it in the ninth.
Luis Polonia led off with a single against Tim Crabtree (2-7) and went to second on Jose Vizcaino's single. Jose Canseco hit into a fielder's choice, beating out a double play when Luis Alicea's throw pulled Frank Catalanotto off the bag at first.
Left-hander Mike Venafro came on and Martinez grounded a single just inside the first-base bag. The Yankees poured out of the dugout in jubilation and the crowd, which booed its team in the eighth inning, celebrated.
Mariano Rivera (7-3) escaped a shaky ninth for the win. With runners on first and second, Vizcaino started a neat double play, moving from second and going to his knees to stop Gabe Kapler's grounder up the middle.
After an intentional walk to Ricky Ledee, Pedro Valdes hit a grounder back to the box that Rivera knocked down and made the play at first.
The Yankees kept up their dominance of the Rangers, winning for the 41st time in 54 games since losing Game 1 of the 1996 division series. New York, which swept the Rangers out of the playoffs the past two years, is 32-9 against Texas at Yankee Stadium since 1994.
The Rangers likely won't be making a return trip in the postseason. Their 68th loss in 115 games already surpasses last year's total by one. The Rangers allowed 10 or more runs for the 22nd time this season, breaking the previous franchise record, set in 1998.
The Yankees' bullpen cost Roger Clemens his seventh straight win for the second time in two starts. He left last Friday's game against Anaheim with an 8-3 lead in the ninth, but the Angels tied the game on Mo Vaughn's three-run homer off Rivera.
Ledee, traded by the Yankees in June, erased a 7-4 lead in the eighth with a three-run shot off Mike Stanton. The Rangers then put runners on second and third without hitting a ball more than 25 feet.
Jeff Nelson committed an error on Bill Haselman's swinging bunt and Posada misplayed Mike Lamb's sacrifice for another error.
After Nelson cleanly fielded Royce Clayton's sacrifice, the fans gave the Yankees mock applause. With runners on second and third, Luis Alicea singled through a drawn-in infield to give the Rangers a 9-7 lead.
Kapler hit a two-run double, and Haselman and Rusty Greer had solo homers off Clemens.
Paul O'Neill had a pair of RBI singles off Kenny Rogers, and Posada added a sacrifice fly and an RBI double. Luis Sojo's double off Jeff Zimmerman made it 7-4 in the seventh.
Rogers gave up six runs, 11 hits and four walks in five-plus innings.