MacKinnon, who scored on all three of his shots, had gone 13 games without a goal, since Jan. 17 in Tampa, when he scored with 6.8 seconds left in regulation to send the game to overtime. The Lightning won that game 3-2 in a shootout.
"I'm very fortunate to get a hat trick," said MacKinnon, who scored once in the first period and twice in the second. "It's definitely a lot of fun and it was cool seeing the hats come on the ice. It's been a while since I had a hat trick. To score a couple feels good. If we didn't get the two points, it would be meaningless."
"It was nice to see that from Nate; he's been kind of snakebitten, and it was good to see him break out," said Duchene, who scored a second-period goal. "I think it's going to be huge for us down the stretch if he can continue to produce. A game like that can get you going. I'm really happy for him."
The Avalanche (26-23-11) have won four of their past five games; they scored 18 goals in the wins. They had 43 shots in the loss, 4-1 to the Los Angeles Kings on Wednesday.
"We're moving our feet offensively, our [defense] is very active, we're really working well as a unit of five, and we're not afraid to put pucks on net," Avalanche coach Patrick Roy. "Tonight we didn't have as many shots on net (18), but I thought we made some great plays offensively."
The Lightning (37-19-6) finished their five-game road trip through the Western Conference 3-2-0.
"If you told me we were going to score four and give up 18 shots in the game, not a chance in the world I thought we'd lose this game," Lightning coach Jon Cooper said. "That about sums it up. Mentally, clearly we were not sharp. It was a tough night for a few of our guys. You have to find a way to fight through that.
"We played well enough to win the game, but we gave them a five spot. That's too bad because we had a really good trip. It stings to end the trip on this note."
The Lightning nearly sent the game to overtime. Brett Connolly scored with 8:17 left in the third period to make it 5-3, Nikita Kucherov drew them within a goal when he scored with 1:02 remaining after goalie Andrei Vasilevskiy went to the bench for a sixth skater, and they kept pressing until the final buzzer against goalie Semyon Varlamov, who had 28 saves.
"It was tough, very stressful at the end," MacKinnon said. "They were coming back, peppered us with shots, but that's what teams do when they're down; it's just the way it goes. We were on our heels a little bit."
Alex Tanguay scored what proved to be the winning goal at 7:20 of the third period. Rookie Dennis Everberg skated down the right wing and passed in front to Tanguay, who banged the puck past Vasilevskiy for a 5-2 lead.
MacKinnon, who has 12 goals, completed his hat trick at 12:50 of the second period on a breakaway off a pass from Ryan O'Reilly. MacKinnon skated down the middle and shot the puck by Vasilevskiy's glove for a 4-2 Avalanche lead.
"I saw Nate flying with speed," O'Reilly said. "You have to give him the puck then, and he made a great play. It's well deserved; he's been working so hard and he wasn't getting the bounces."
MacKinnon was standing at the edge of the crease when he deflected in O'Reilly's shot at 3:10 of the second period for his second goal to put the Avalanche in front 2-1.
Duchene scored 29 seconds later after he intercepted Tampa Bay defenseman Nikita Nesterov's pass in the Lightning end.
Tampa Bay responded after Colorado turned over the puck in its own end. Kucherov took a shot, and Varlamov made the save, but Tyler Johnson jammed in the rebound at 5:51.
MacKinnon tied the game 1-1 at 16:21 of the first period. He accepted a pass from Gabriel Landeskog, skated into the Lightning end and used his speed to get by Nesterov and Jason Garrison before beating Vasilevskiy with a backhand to the glove side.
"It was kind of a foot race," MacKinnon said. "I tried to get a quick backhander off, I wasn't aiming. It definitely felt good to make it 1-1. The puck was finding me tonight. I owe it to those guys, my teammates."
The Lightning took a 1-0 lead at 10:53 of the first period on a goal by Ondrej Palat after Avalanche defenseman Brad Stuart didn't handle a pass inside the blue line. Johnson passed to Palat moving down the right wing for a shot that beat Varlamov to the short side.
Palat has four goals and three assists in a five-game point streak.
"I allowed too many goals on 18 chances," Vasilevskiy said. "That's not many shots for a goalie. I have to be better. Eighteen shots and five goals, that isn't good. It's done, and I can't do anything about them. I saw the shots, I didn't stop them."