Carter is second in the NHL with 22 goals, two behind Buffalo's Thomas Vanek.
Paul Stastny and David Jones scored for the Avalanche, who had won three of four - including a 2-1 victory Monday at Detroit.
The Avalanche had beaten the Flyers five straight times. Philadelphia's previous win over Colorado was 2-1 in overtime in 2002. The Flyers hadn't won a meeting in Philadelphia since 1999, also in overtime, 5-4.
Philadelphia's Antero Niittymaki, who started in place of flu-ridden Martin Biron, stopped 29 shots for his sixth win in his last seven games.
Peter Budaj, who has started in 26 of Colorado's 31 games, made 19 saves.
Stastny, who leads the Avalanche in scoring with 27 points, put Colorado ahead with an unassisted power-play goal at 9:23 of the first period. His eighth goal came 6 seconds after Darroll Powe was called for hooking.
The Flyers responded with a power-play goal by Knuble at 11:37 and a short-handed score by Carter at 18:12 to take a 2-1 lead.
Knuble scored his 100th goal as a Flyer, poking in a shot from the crease after taking a cross-ice pass from Richards on a power play.
Carter scored on a one-timer after Simon Gagne picked up a loose puck deep in the Flyers' zone, skated in and slid a pass to Carter in front of the circle.
The Flyers extended their lead to 4-1 with a pair of bizarre goals within a span of 1:18 midway through the second period.
Lupul's shot from in close bounced off the crossbar straight down into the net at 11:24.
Richards was given credit for a goal at 12:42 when Colorado's Scott Hannan inadvertently knocked the puck past Budaj during a scramble.
Colorado made it 4-2 when Jones deflected T.J. Hensick's shot between Niittymaki's pads with 1:21 left in the period.
Gagne deflected Kimmo Timonen's slap shot from the blue line on a power play for his 16th goal at 2:14 of the third period. Timonen, who had two assists, has six assists in his last two games.
Notes: Richards extended his points streak to eight games (seven goals, eight assists). ... Colorado killed off 12 straight penalties before Knuble's power-play goal. ... The Avalanche are in the midst of a four-game road trip, their second-longest of the season, with games remaining at Tampa Bay and Florida. ... The Flyers lead the NHL with 12 short-handed goals, one less than their 2007-08 total. ... The Flyers recalled G Scott Munroe from the Philadelphia Phantoms, their American Hockey League affiliate.