Hayward came off a down-screen by Derrick Favors to shoot an 18-foot jumper with 4.5 remaining. He didn't miss that one.
A floater in the lane by Sacramento's James Johnson missed as time expired.
Hayward finished with a game-high 23 points on 7-of-16 shooting and, more importantly, gave the Jazz (7-6) their third straight win going into Saturday's rematch in Sacramento.
Hayward led a balanced Jazz effort that saw Jamaal Tinsley replace Mo Williams, who was limited to seven minutes after spraining his right ankle in the first quarter, and contribute 12 assists and force a key steal with 12 seconds left in the game.
"I thought we won it," coach Tyrone Corbin said, "with a lot of grit, gut, staying together, understanding the time and moment of the game and what we had to do."
A switch in the starting lineup proved mutually beneficial for both of the players involved. After coming off the bench for each of the Jazz's last two games, Marvin Williams scored 20 points on 6-of-12 shooting. Derrick Favors, meanwhile, scored 16 points and grabbed 13 rebounds in 28 minutes.
Earl Watson made his season debut for the Jazz, finishing with 2 assists in 10 minutes. Watson last played on Easter Sunday for the Jazz before undergoing major knee surgery to repair a torn meniscus in his right knee. With 9:23 left in the game, Watson found Hayward for a back-door alley-oop dunk, which Watson said was "when I really felt comfortable."
Sacramento led 95-82 with 7:09 remaining after a 3-point basket by former BYU All-American Jimmer Fredette, who was enthusiastically booed by Jazz fans each time he touched the ball. Fredette finished with 10 points and made 3 of 4 3-point attempts in 17 minutes.
However, the Jazz responded to Fredette's jumper with a 19-4 run, keyed by good defense from Favors and others. The Jazz at one point got nine straight defensive stops. They took a 102-99 lead with 58.8 seconds left on a pair of free throws by Al Jefferson, who finished with scored 19 points and 8 rebounds.
Hayward, who came off the bench for the third straight game, continued his hot play. He scored 15 points in each of the Jazz's previous two victories and was even better against the Kings.
"I would say three OK games," Hayward said. "There's still a lot of room for improvement. Missed a lot of shots tonight."
Tinsley, who reached double-digit assists for the third time this season, had no lack of confidence in Hayward, though. With Jefferson, the first option on the play, double-teamed in the post, the veteran waited patiently for Hayward.
"I didn't pick my dribble up," he said. "I knew Gordon was going to come up, and he happened to hit a good shot for us."
Jazz 104, Kings 102
R Utah extends its winning streak to three after Gordon Hayward hits the go-ahead jumper with 4.5 seconds remaining.
• Former BYU star Jimmer Fredette scores 10 points in 16 minutes, including three 3-pointers. For a story about Fredette, see Page D9.
Jazz at Kings
P Saturday, 8 p.m.
TV • ROOT Sports, NBA TV
Radio • 1280 AM, 97.5 FM
Records • Utah (7-6), Sacramento (3-9)
Season series • Jazz 1-0
About the Jazz • Utah is 2-6 on the road, while having won all five games at EnergySolutions Arena. ... Gordon Hayward scored a season-high 23 points against the Kings on Friday night. ... Jamaal Tinsley has recorded double-digit assists in back-to-back games.
About the Kings • Six players scored in double digits against the Jazz on Friday, including Marcus Thornton and his team-high 18 points. ... The Kings have lost six of their last seven games.