DENVER (AP) -- Danilo Gallinari's last-ditch shot was nowhere near the basket until Kenneth Faried got his hands on it.
Faried rebounded Gallinari's errant shot in the lane for a putback with 5 seconds remaining to give the Denver Nuggets a 103-102 victory over the Milwaukee Bucks on Wednesday night.
"I just knew I had to be around the rim for whatever happened," Faried said. "Miss or make, I was right there in position to grab the rebound."
Khris Middleton's shot from the corner rimmed out at the buzzer as the Bucks lost for the sixth straight time in Denver.
"I felt like I got a good look off it," Middleton said. "I felt like it had a chance to go in. It just didn't. I missed it, move on."
Gallinari had 25 points to lead the Nuggets and Faried finished with 19. Rookie guard Emmanuel Mudiay added 16 points and 11 assists for his second double-double.
"Thank goodness we had just enough in us to come out of here with the win," Nuggets coach Michael Malone said. "Middleton missed a great shot at the end but that's life in the NBA. If that shot goes in, it is a much different locker room."
Jerryd Bayless had 14 of his 22 points in the fourth quarter for Milwaukee while Greg Monroe added 18 and Greivis Vasquez had 15.
Before the game the Nuggets announced forward Wilson Chandler, a key player for Denver over the last five seasons, would undergo season-ending surgery to repair a labral tear in his right hip. He suffered the injury in the preseason.
The Bucks, who knocked down seven of every 10 shots in the first half, led 69-56 after Middleton drained his third 3-pointer of the game a minute into the third quarter.
But Milwaukee cooled off and Denver began chipping away at the deficit. Gary Harris hit successive 3s, and later in the third quarter, the Nuggets put together a 12-0 run to go in front 81-75. Faried scored 10 points during the burst, including the tying and go-ahead baskets.
Gallinari punctuated the Nuggets' third-quarter resurgence with a 3-pointer that allowed Denver to take an 87-80 lead into the final period.
The Bucks fought back to tie it at 98-all on a 3-pointer by Bayless and went in front on a jumper by Johnny O'Bryant III with 1:21 to play.
After Mudiay made three of four free throws in separate trips to the line to put Denver back on top by a point, Giannis Antetokounmpo hit a jumper in the lane over Faried with 17.5 seconds remaining. With the clock ticking down, Gallinari launched an air ball from the corner. Faried soared up in the lane to grab it cleanly and put it back in for the game-winner.
"Khris did a great job keeping Gallinari in front of him forcing him into a tough shot," Bucks coach Jason Kidd said. "Unfortunately for us, that bad shot landed right in Faried's hands and he had an easy putback layup."
Shooting an uncanny 70 percent from the field over the first two quarters, the Bucks opened a 64-53 lead. They hit eight of their first 11 3-pointers, including three by Vasquez.
Bucks: Their 32-point first quarter was a point shy of their season high for the period. ... F Jabari Parker was rested on the second night of a back-to-back as he continues his return from a left ACL injury suffered 11 months ago. ... G Michael Carter-Williams continues to recover from a left ankle sprain that has sidelined him for the past five games. ... Milwaukee finished shooting 53.2 percent from the field.
Nuggets: G Jameer Nelson missed a second straight game with a lower back injury. ... C Joffrey Lauvergne remains sidelined with a lower back injury that has kept him out the last five games.
Bucks: Host Cleveland on Saturday.
Nuggets: Host Houston on Friday.