The victory moves the Kings back into playoff position, passing Minnesota to move into eighth in the Western Conference.
Calgary's seventh shooter was defenseman Jay Bouwmeester and after he hit the goal post, Kings coach Terry Murray turned to Williams, who snapped a shot past Miikka Kiprusoff to win it.
Rob Scuderi and Dustin Brown also scored for Los Angeles, which is 2-0-1 through its first three stops on a 10-game road trip.
Los Angeles had lost 10 games in a row at the Saddledome going back to 2005.
Alex Tanguay had two goals and an assist to lead Calgary. Robyn Regehr also scored for the Flames, who missed a chance to move into a playoff position for what would have been the first time since Oct. 29.
Brendan Morrison had three assists, extending his point streak to seven games.
Both teams entered the game with 58 points each, part of a three-way tie for ninth place in the Western Conference.
Three times Los Angeles took a lead and three times Calgary came back to tie it.
Tanguay's second goal of the night at 11:15 of the third period tied it 3-3, with the Flames already on the power play and a delayed penalty coming up to Jarrett Stoll for hooking.
Morrison flicked a no-look backhand pass toward the front of the net that slipped through untouched and landed on the stick of Tanguay, who rifled it in as goalie Jonathan Quick slid across.
After picking up a pair of assists in the first period, Williams' 19th goal of the season at 11:02 of the second period broke a 2-2 tie.
After converting their first man advantage, the Kings broke a 2-2 tie at 11:02 of the second period on what was virtually another power-play goal.
Coming seconds after Rene Bourque's penalty had expired, Williams' goal on a rebound from a scramble in front of the Flames net was the result of an extended stretch of pressure in Calgary's end.
Calgary trailed 2-1 entering the second period, but it only took them 45 seconds to get back even.
Pressure by the Flames' top line led to a goal by Tanguay, who was set up in front by Morrison and had the entire top half of the net to shoot at with Quick sprawled on his belly.
Los Angeles took its second lead of the night at 6:17 of the first period when Brown's power-play goal put the Kings ahead 2-1.
Brown first whacked a bouncing puck wide, but collected it again and put just enough on it to get it over the goal line.
The game got off to an unusual start.
In a matchup between two of the hottest goaltenders in the league in the past couple weeks, each team scored in the game's opening 90 seconds with the goal scorer for each team being the most unlikeliest of players.
At 0:39, Scuderi lobbed a shot toward the Flames net that fooled Kiprusoff and squeezed between his pads.
It was the second goal of the season for Scuderi, who had only scored once in his previous 205 games and had never scored more than once in any of his six previous NHL seasons.
It took the Flames only 42 seconds to tie it with Regehr getting an equally rare goal.
Unable to see threw traffic in front, Quick never moved on Regehr's rising wrist shot from the blue line that went in just inside the goal post.
It was the first goal in 65 games for Regehr, who had only scored twice in his previous 224 games.
Notes: Fan favorite Craig Conroy, who retired Friday, received a lengthy standing ovation when, during a break in play in the first period, he was shown on the scoreboard video screen sitting among the Flames management. ... Lance Bouma, 20, from Provost, Alberta., made his NHL debut for Calgary. He played left wing on a line with Mikael Backlund and Tom Kostopoulos. ... Calgary LW Niklas Hagman (lower body) missed his second straight game. ... Calgary coach Brent Sutter coached his 300th NHL game. ... Brown is the lone player remaining from the Kings team that last won in Calgary on December 21, 2005. ... The Kings improved to 17-0-0 when leading after two periods.