The Nets, behind a sensational performance from Deron Williams and a bounce-back game from Brook Lopez, were comfortable winners in Friday night’s first of four meetings between the local teams this season, beating Carmelo Anthony and the Knicks 110-99 in front of a sellout crowd of 17,732 inside Barclays Center.

Williams finished with 29 points and six assists and Lopez had 20 points and nine rebounds for the Nets (3-2), who recovered nicely from letting Wednesday’s game against the Timberwolves slip away from them in the final minutes. They pounded the Knicks from the start, taking a double-digit lead after the first quarter and maintaining it throughout the second half.

“I just wanted to be aggressive,” said Williams, who scored 12 points in the third quarter to help put the game away. “That’s all it was. I thought the first couple games we played, I kind of died down in the second half, so I wanted my energy to be up in the second half, and I felt like we needed somebody to kind of step up, so I took that upon myself.”

Williams certainly did that, shredding the Knicks’ defense — and Iman Shumpert specifically — throughout. With the Knicks missing point guards Jose Calderon (calf) and Pablo Prigioni (ankle) because of injuries, coach Derek Fisher chose to insert Tim Hardaway Jr. into the starting lineup in place of Shane Larkin. He slid Shumpert to the point and gave the Knicks a bigger backcourt in an attempt to combat the size the Nets have across their lineup.

But Williams had his way with Shumpert and whoever else the Knicks threw on him, constantly finding his way to the rim and either scoring or getting to the foul line.

“He kept getting ball screens and he got to every spot on the floor he wanted to, and then he got his confidence going,” Shumpert said.

Carmelo Anthony finished with 19 points to lead the Knicks (2-4), but he finished just 5-for-20 from the field and never seemed comfortable, and is now 18-for-64 in his last three games — all Knicks losses.

“I’m still trying to figure it out,” Anthony said of his shooting struggles.

But while Anthony was floundering, Williams was excelling, continuing his strong start to the season. He seems to have put the past two years’ worth of ankle troubles firmly behind him.

Williams has now finished with at least 15 points and six assists in each of his first five games, something he hadn’t done since the 2012-13 season, and admitted after the game that he’s feeling better every time he steps on the court after offseason surgery on both ankles.

“I’m getting there,” Williams said with a smile. “Every game is a process. It’s still early in the season, but I definitely feel like I’m gaining confidence and trying to get that rhythm back.”

Lopez also had a strong showing after going 5-for-14 from the field, scoring 10 points and committing two harmful fouls in the final minute of Wednesday’s loss. He had little trouble scoring or getting to the line against any of the several bigs the Knicks threw at him.

The crowd, as it has been for each of the five games played at Barclays Center between these teams over the past three years, was basically a 50-50 split in terms of fan representation. But it was the Nets fans who had the better night, and could be heard making the most noise at the end of the game.

This one was miserable to watch no matter who you rooted for right from the opening tip, as the teams took turns making mistakes throughout. The Nets, after missing 12 of their first 14 shots Wednesday against Minnesota, committed six first-quarter turnovers, while the Knicks shot an abysmal 8-for-25 (32 percent) from the field in the opening 12 minutes.

The Nets managed to open up a 30-20 lead after one thanks to going 6-for-7 from behind the 3-point line. But the game got no easier to watch as it moved into the second, even as the Nets slowly pulled away. The Knicks failed to keep in front of their 3-point shooters and Williams tore the visitors to shreds.

“I think it’s the effort,” said Amar’e Stoudemire. “We have to put in more effort on the defensive end, for sure. Obviously the offense is something we’re learning … but while we’re in the process of doing that, we have to make sure we have that effort defensively.”

With the Knicks trailing by 13 at halftime, Fisher tried to switch things up, putting Stoudemire and Quincy Acy in the game to start the second half in place of Jason Smith and Samuel Dalembert. But it didn’t change much, as the Nets quickly went on a 9-2 run to start the half to lead by 20.

Anthony and Stoudemire combined for 17 points in the third to try and keep the game close, but the Nets got six straight points from Williams to close the third up 86-68, leaving the final 12 minutes as nothing more than a formality.