SACRAMENTO, Calif. — Gordon Hayward made up for a costly foul by hitting a tiebreaking shot with 2 seconds to play that helped the Boston Celtics overcome the absence of injured star Kyrie Irving in a 111-109 victory over the Sacramento Kings on Wednesday night.

Hayward fouled Buddy Hield on a 3-point attempt with 7.6 seconds left, allowing the Kings to tie the game. Boston had no timeouts and went the length of the floor to score on Hayward’s bucket.

Harrison Barnes then missed a 3 at the buzzer, giving the Celtics their second win in two nights to start a four-game California swing.

One night after beating two-time defending champion Golden State by 33 points to open the trip, the Celtics managed to hold off the feisty Kings with Irving sidelined by a bruised left thigh.

Jayson Tatum led Boston with 24 points, Al Horford had 21 points, 11 rebounds and seven assists, and Hayward finished with 12 points. Boston had lost five of six before beginning this trip.

Barnes scored 24 points and Hield added 23 for the Kings, who have lost four of five and trail San Antonio by four games in the race for the final Western Conference playoff spot.

The Kings erased a six-point deficit in the final three minutes thanks in part to two drives by De’Aaron Fox and a hustle block by Hield that prevented a fast-break layup for Marcus Smart.

Hield’s free throws then tied the game before Hayward delivered the game-winner for Boston.

The game was tight throughout, with neither team taking a double-digit lead until Hayward scored on a fast-break layup to put Boston up 82-72 late in the third quarter.

The Kings responded with a 3 from Barnes and a spinning layup from Fox following Harry Giles’ block on Jaylen Brown to cut the deficit in half. Sacramento missed a chance to get even closer when replay wiped out an apparent buzzer-beater by Hield off an inbounds pass with 0.5 seconds left in the quarter.

Sacramento tied the game early in the fourth, setting the stage for the tight finish.