Houston had dropped 15 straight before its winning streak.
“It’s all about growth," Gordon said. “Whenever you see a streak like this, you see and know what it takes to win. So you can never forget moments like this. And you can’t never forget the moments beforehand when we lost all those games because during that time, it wasn’t fun and it’s fun now and we’ve got to keep it going."
Cole Anthony scored 26 points for the Magic, who have lost eight of nine.
Houston had a 13-point lead with about four minutes left after a big stretch by Garrison Mathews. But Anthony then scored scored eight points in a 13-0 spurt by the Magic that tied the game at 114-114 with 47 seconds to go.
Orlando had three blocks and forced three turnovers in the run.
The Rockets ended a scoring drought of 3 1/2 minutes with a floating jumper by Gordon to regain the lead with 31.4 seconds remaining. But a dunk by Mo Bamba tied it again.
Gordon then dribbled into the lane and knocked down the decisive jumper.
“You’ve got to make a play in a situation like that," Gordon said.
The Magic had a chance to win at the buzzer, but Anthony’s 3-point attempt clanged off the rim.
Houston coach Stephen Silas is impressed with his team's improvement after a difficult start.
“They’re definitely getting more confident but they’re also getting more comfortable," he said.
Orlando coach Jamahl Mosley said Anthony's fearless approach lifts the team.
“I think it is a reflection of his work ethic," Mosley said. “It’s a reflection of his confidence. And there’s also the confidence that his teammates have in him to be willing to take those shots."
Christian Wood had 20 points for the Rockets and Matthews scored 10 of his 16 points in the fourth quarter.
Houston was up by one at the end of third and the Rockets had a five-point lead after a three-point play by Alperen Sengun with about seven minutes to go.
The Magic got a 3 from Anthony after that, but Mathews scored the next seven points to extend Houston’s advantage to 109-100. Mathews got things going when he was fouled on a 3-pointer and crashed to the ground as the ball went through the net. He made the free throw and hit another 3 after a miss by the Magic.
Anthony made a free throw before Mathews hit another 3 to push it to 112-101. Wood added a basket before the Magic rediscovered their offense.
The Magic led by as many as eight points in the third quarter, but Chuma Okeke's layup at the end of the period drew Houston within 84-83.
Rockets: Rookie Jalen Green missed his fourth straight games with a strained left hamstring. Silas said Green was getting better but would remain out at least one more week. ... Kevin Porter Jr. scored eight points in the first half but didn’t play after halftime because of a bruised left thigh.
HE SAID IT
Silas on the success of Mathews after poor shooting earlier in the game: “He was so upset that he was missing all those shots early. He told me he was going to make one (3-pointer) and he made three. He’s just relentless and not afraid."
Magic: Visit Golden State on Monday night as they continue a five-game trip.
Rockets: Host New Orleans on Sunday night.
Would a deal centered around Ben Simmons and James Harden make sense?
Israel Gutierrez outlines how a possible Ben Simmons for James Harden trade could come about.
Daily notes for Wednesday: Curry, Thompson splash Pistons
Your essential daily recap of last night's NBA action, and roster tips for Wednesday night's matchups.
NBA best bets for Wednesday: Rolling with Joel Embiid
Our experts pick their best bets and props for Wednesday's 13-game NBA slate.