Los Angeles is in last place in the Western Conference, eight points behind the Minnesota Wild for the second wild card into the Stanley Cup Playoffs.
McAvoy backhanded DeBrusk's pass at 18:47 for a 3-2 lead after Iafallo tied the game 2-2 on a rebound of Paul LaDue's shot at 15:37 of the third period.
"It wasn't the prettiest of goals but we didn't care at that point," DeBrusk said.
The Kings got a power play 23 seconds after Iafallo scored when Brad Marchand hooked Jeff Carter, but the Bruins did not allow a shot on goal.
"Very proud of how we played in the third," said Rask, who is 11-0-2 in his past 13 starts and has not lost since Dec. 23. "Even after they tied the game, a few minutes left and then we get a penalty, we did a great job with that penalty kill. It just shows how resilient our group is."
Kings center Anze Kopitar broke his stick in frustration after McAvoy scored his third goal, which Kopitar attributed to frustration with his execution on the go-ahead goal and on the power play that preceded it.
"With four minutes left and having a power play in a tie game we have to find a way to score," Kopitar said. "We didn't even get in the zone. That's embarrassing."
Patrice Bergeron made it 4-2 at 19:23.
The Bruins took a 1-0 lead at 5:31 of the first period when DeBrusk set an NHL career high with his 17th goal of the season.
Kovalchuk tied it 1-1 on the power play at 10:37 of the second period with a wrist shot from the left circle.
Marchand scored his fourth goal in the past five games to restore a 2-1 lead for Boston at 16:15 after Rask made an impressive save with the paddle of his stick to deny Iafallo at 14:55.
"I think that was the craziest two-pad stack save I've ever seen," DeBrusk said. "I had a front row view to it. It was actually my guy. There's a reason why he's been a Vezina winner, and he was the biggest reason why we won the game tonight, obviously. He was holding the fort down and it was impressive to watch."