Carson Palmer went down in the final period, then backup Drew Stanton and the Arizona defense rallied the Cardinals with three touchdowns over a span of 3 minutes, 48 seconds.
Rookie John Brown's diving grab of Stanton's 48-yard touchdown pass put the Cardinals (8-1) up 17-14 with 7:40 to play. The pass came on the first series after Palmer hurt his left knee while trying to avoid the rush.
Palmer was able to walk off the field but a short time later was taken to the locker room on a cart.
Patrick Peterson got his first two interceptions of the season, returning the second one 30 yards for a touchdown to make it 24-14. Moments later, Austin Davis fumbled and Antonio Cromartie returned it 14 yards for a score as Arizona outscored the Rams 21-0 in the fourth quarter.
St. Louis (3-6) was shut out in the second half.
At 8-1, the Cardinals have the best record in the NFL and their best after nine games since going 11-1 as the Chicago Cardinals in 1948.
Palmer's injury loomed over everything, though.
He was playing some of the best football of his career and, on Friday, signed a three-year contract extension worth a reported $50 million with $20.5 million guaranteed.
On third at the Rams 28, Palmer dropped back to pass, then tried to avoid blitzing safety Mark Barron. The quarterback's leg gave way and Barron touched Palmer for a sack.
Palmer was 25 of 36 for 241 yards, with no touchdowns and just his third interception of the season.
Arizona's Larry Fitzgerald caught nine passes for 112 yards.
Davis completed 17 of 30 for 216 yards and a TD with two interceptions and a lost fumble.
On Peterson's second interception, the ball bounced off the hands of the Rams' Kenny Britt. Peterson caught it and raced to the end zone for the score. On St. Louis' next possession, Kareem Martin hit Davis and the ball came free as he tried to pass. Cromartie picked it up and ran in for the score to put Arizona up 31-14 with 3:58 to play.
Arizona has outscored opponents in the fourth quarter 91-34.
Stanton, who started three games while Palmer was out with a shoulder injury earlier in the year, completed an 11-yard pass, ran for four yards, then completed a 26-yarder to John Carlson on his first three plays. Then Stanton let fly for the speedy Brown, who beat defenders and laid out to catch the ball as he crossed the goal line.
Jared Cook, who caught seven passes for 141 yards and two touchdowns against Arizona in last season's opener, got behind rookie Deone Bucannon for a 59-yard touchdown pass with 1:50 left to give St. Louis a 14-10 halftime lead.
The TD came after Arizona had scored 10 straight points to take a 10-7 lead on Chandler Catanazaro's 43-yard field goal with 4:52 left in the half. With the kick, Catanazaro tied the NFL record for consecutive field goals to start a career at 17 before missing a 53-yarder on the play after Palmer was hurt.
Cardinals rally past Rams, 31-14
CardinalsSource Top Stories
Watford to replace injured Mathis SundayBruce Arians ruled Evan Mathis out for Sunday's game in Buffalo.
CardinalsSourceFriday at 4:03 PM
Bettcher sizes up BuffaloAfter allowing just seven points to Tampa Bay last week, the Arizona Cardinals travel to take on a Buffalo offense that scored 31 points in week two.
CardinalsSourceFriday at 10:32 AM
Cardinals prepare for first east coast tripThe Arizona Cardinals went 4-1 in five east coast trips during the regular season last year.
CardinalsSourceThursday at 2:38 PM
Mathieu's role still fluidThe Arizona Cardinals have yet to play Tyrann Mathieu as a slot corner this season.
CardinalsSourceThursday at 2:15 PM