RJ Barrett recorded a career-best with 28 points and the New York Knicks used a 40-point first quarter to build a lead they relinquished only momentarily in a 119-104 victory over the Golden State Warriors on Thursday night in San Francisco.

All five Knicks starters scored in double figures, including Mitchell Robinson with 18 points and Julius Randle with 16 points, as New York opened a four-game Western swing with an impressive win. The Knicks earned their third consecutive win.

Stephen Curry had a game-high 30 points but shot just 5-for-14 on 3-point attempts for the Warriors, who were coming off back-to-back wins over the Los Angeles Lakers and San Antonio Spurs over the previous three days.

Reggie Bullock hit four 3-pointers for New York, including three in the first five minutes as the Knicks were opening the game on an 18-8 run.

The visitors went up by as many as 11 in the first period and were caught just once the rest of the night, that coming at 55-all after a pair of Curry free throws with 2:01 remaining in the half.

New York’s Elfrid Payton contributed a 3-pointer to an 8-2, half-closing run that re-established a six-point advantage, and the Warriors fought an unsuccessful uphill battle the rest of the night.

Barrett’s 28 points were one more than he scored on two occasions as a rookie last season. He shot 10-for-17 overall and 2-for-3 on 3-point attempts.

Payton finished with 15 points, Bullock had 12 points, all on 3-pointers, and Alec Burks chipped in with 11 for New York, which logged its second-largest point total of the season. The Knicks exploded for 130 points in a 20-point win over Milwaukee last month.

Randle was the game’s top rebounder with 17, missing a triple-double by one assist. Nerlens Noel added 11 rebounds to complement six points and four blocks off the bench.

Andrew Wiggins had 17 points to go with a team-high nine rebounds while James Wiseman totaled 15 points and Eric Paschall 12 for the Warriors. Golden State’s Draymond Green was ejected in the second quarter after receiving his second technical foul of the night.

The Knicks outshot the Warriors 46.3 percent to 38.4 percent overall and 45.8 percent to 23.7 percent on 3-pointers.

Green’s ejection occurred during a foul-marred first half in which 48 free throws were shot. New York led 63-57 at the break, the result of having made 21 of 27 free throws while the Warriors were 15 of 21.