Bojan Bogdanovic scored 25 and Alec Burks had 17 for Detroit, who have now lost five of their last six games.
The Pistons are 0-7 on the road this season.
“We shot poorly as a team from the 3-point line (7 for 31). As a team we played better defense in the second half,” Bogdanovic said.
New York went on an 11-2 run to go up 79-62 on a Randle layup with 7:54 remaining in the third quarter and a pair of Derrick Rose free throws gave the Knicks a 94-80 advantage at the end of the period.
The Pistons opened the fourth quarter with a 15-7 spurt and capped it with consecutive 3-pointers from Isaiah Livers that cut the deficit to 101-95 with 7:02 left in regulation.
A stepback jumper and a pair of free throws by Bogdanovic made it 114-110 with 1:42 to play.
Barrett then knocked down a pair of free throws and a 3-pointer by Quentin Grimes in front of the Pistons bench with 40 seconds made it 119-110 to seal the Knicks victory.
Barrett scored 12 points in the first quarter, including seven during a 14-5 run that helped the Knicks take a 30-26 lead at the end of the period.
He added eight points during the second quarter, nailing a 3-pointer with eight seconds left to give New York a 68-58 halftime lead.
“(Barrett was) great downhill, attacking the basket, a lot of pressure on the rim,” Knicks coach Tom Thibodeau said. “We’ve been terrific with scoring on the paint all year long and a big part of it is the pressure that he puts on people.”
Pistons: Detroit guard Cade Cunningham was held out of Friday night’s game due to left shin soreness. … The Pistons outscored the New York bench 53-34.
Knicks: Isaiah Hartenstein had 12 rebounds. … New York has won its last eight meetings against the Pistons. The previous loss was Nov. 6, 2019 at Detroit.
Pistons: Host the Boston Celtics on Saturday night.