Randy Foye hit a game-winning, buzzer-beating, three-pointer on Monday night, as the Brooklyn Nets scored a gritty 120-118 win over the Charlotte Hornets at Barclays Center.

Down 118-117 with 2.3 seconds to play, Bojan Bogdanovic (game-high 26 points) inbounded to the crafty vet, who chucked it up and watched it drop, ending the Nets five-game losing streak in the process.

“These are tough games against a really good team,” Coach Kenny Atkinson said. “I’m thrilled with our group, we went through some rough times recently so to go out and get a win like this – and the way we got it – is special.”

Foye’s hero shot was a high-voltage jolt of electricity through Barclays Center, but Monday’s win was powered by gutsy second-half performances from Brook Lopez (21), Sean Kilpatrick (23) and Bogdanovic. The Nets trio combined for 47 of the Nets 66 second-half points, pulling Brooklyn out of a 14-point hole en route to the win.

“We really came together,” Lopez, who did some heavy lifting during a 10-point, two-assist, fourth quarter, said. “We were moving the ball, we were so unselfish and we really took full belief and trust in one another. They obviously started coming in and doubling from the baseline, but Kilpatrick made great passes… and guys made themselves available when I was in the double. We moved the ball and ball swung so well.”

The Nets had 16 of their 26 assists in the second half – 10 in the fourth quarter – doing exactly what Lopez said. They shared the ball and found the open shot, highlighted by a pair of critical three-pointers by Kilpatrick and Bogdanovic putting the Nets up 117-113 with 1:06 to play.

That’s where things got tense, as Nicolas Batum – who led Charlotte with 24 points – hit a three to make it 117-116 with 32.7 to play and Cody Zeller’s put-back gave the Hornets a 118-117 lead with 3.5 seconds on the clock. The Nets had previously missed two straight shots that would have likely sealed it, but they didn’t flinch.

“It was tough seeing Zeller put that basket down, but the way our team maintained focus and our mental strength was fantastic,” Lopez said. “It was great validation.”

Foye said he was late to guard Zeller on the put-back, so he was relieved to get the winning shot, even if he said the play was drawn up for Lopez.

The second half and fourth quarter resiliency counteracted a tough start for the Nets, who were down 40-31 after the first quarter and 63-54 at the half. Atkinson said the difference was the Nets simplifying their game.

But for all the good feelings in Monday’s come-from-behind win, the Nets did see point guard Jeremy Lin leave the game with a strained left hamstring and not return. Coach Atkinson didn’t have a post-game update on the point guard, who missed 17 games earlier this season with a hamstring injury.

“It’s frustrating,” Foye said. “Watching a guy work so hard to get back, just respect, just leadership every single day. On the court, off the court. For him to go out again with the same thing is like, c’mon man. Why? At the end of the day, Jeremy is a resilient, strong person and he’s going to get through this.”

The Nets travel to Chicago to visit the Bulls on Wednesday night. Tipoff is at 8 p.m. ET.