OAKLAND, Calif. -- The Orlando Magic were out of rhythm and running out of time, though the defending Eastern Conference champs didn't seem bothered much.
With Vince Carter scoring at will and playing like he did in his younger days, Orlando could afford to be relaxed down the stretch.
Carter had 27 points, including the go-ahead 3-pointer with 3 1/2 minutes to play, Mickael Pietrus scored a season-high 22 points and the Magic rallied to beat the Golden State Warriors 126-118 on Saturday night.
"I'm not a big stat guy anymore," said Carter, who added seven assists and five rebounds. "I was just trying to stay aggressive, especially late getting to the free throw line, and trying to attack the gaps. Once we came to our senses and put up more of a defensive stance, we didn't allow them to do much more."
Dwight Howard added 17 points and eight rebounds, and Jason Williams had 12 points, eight rebounds and five assists. The Magic, who outscored the Warriors 17-4 down the stretch, have won five straight to improve to 16-4 overall and 9-2 on the road.
It wasn't easy.
Orlando had to overcome another stellar night by Golden State guard Monta Ellis and a career night from Anthony Randolph while playing much of the final two quarters with Howard, the centerpiece of the Magic's offense, on the bench in foul trouble.
"We got a little lucky and hung around and stayed in the game until we were able to get the last push that we needed," Orlando coach Stan Van Gundy said. "It was just crazy. We finally gained some composure and made plays on both ends to dig it out."
Carter and Pietrus, who spent his first five seasons with the Warriors, helped pick up the scoring slack when Howard ran into foul trouble midway through the third quarter. The duo scored Orlando's final 15 points in the third, then came up big after the Magic fell behind 114-109 with 6:05 left.
After Anthony Johnson's layup pulled Orlando to 114-111, Pietrus made a tying 3-pointer and Carter followed with his own trey. After a pair of Golden State misses, Carter added two free throws and Pietrus connected on his fourth 3-pointer to make it 122-114.
"We let them make a push there, but you have to keep weathering the storm," Carter said. "We didn't do a great job on the defensive end, but at the same time, late in the game, when we needed some defensive stops and some rebounds, we were able to do so."
Ellis had 33 points and seven assists, and Randolph added a career-high 28 points and 13 rebounds for Golden State. It's the fifth time in eight games Ellis has topped the 30-point mark.
Matt Barnes, another former Warrior, had 11 points and six rebounds for Orlando, 14-6 in its last 20 games against Golden State.
Ellis did his best to put the Warriors in range for the upset, repeatedly burning the Magic with midrange jumpers and beating Orlando's defense with his speed.
Golden State, which will embark on its five-game trip without coach Don Nelson, led by four early in the fourth quarter and were up 114-109 following an 18-foot jumper by Randolph and a layup by Corey Maggette. The Warriors went cold after that, however, and the Magic rallied behind Carter and Pietrus.
"I don't think we were pressing," said Golden State guard Stephen Curry, who had 13 points. "We just made some unfortunate mistakes at the wrong time. We played well for 45 minutes but we've got to find out how to finish games."
Orlando scored 42 points in the first quarter behind 12 points apiece from Howard and Williams and was up 61-46 midway through the second quarter before the Warriors inched their way back at the free throw line.
Golden State managed just three baskets over the final 8 minutes but went 18 of 22 at the line and were within 72-64 at the half. Randolph went 8 of 9 from the line and had 18 points in the half, Maggette added nine points all on free throws and Ellis was 7 for 9 at the line with 15 points.
Howard had 16 points when he picked up his fifth foul on a push-off call midway through the third quarter and the Magic leading 85-80. Pietrus and Carter took over offensively for Orlando and scored the team's next 12 points but Golden State closed out the period on an 18-8 run to take control.
Ellis had nine points during the burst while Radmanovic made a 3-pointer and added a breakaway dunk following a turnover by Jason Williams to put the Warriors ahead 98-85.
The already injury-depleted Warriors also were without their third-leading scorer, guard Anthony Morrow, who flew to North Carolina on Friday following a death in his family.