Five points separated the Nets and the Bucks in their home-and-home set, and Brooklyn came away with two straight last-second victories.

Deron Williams scored 23 points and the Nets escaped with a 97-94 victory on Wednesday night after Milwaukee's Monta Ellis missed a chance to tie the game with three foul shots in the final seconds.

"We did a good job of closing the game until the very end," Nets interim coach P.J. Carlesimo said. "We made it interesting. We got ourselves an 11-point lead and then did a poor job closing that. It's hard to keep coming back, coming back, coming back, but we did it."

Williams made two free throws and a 3-pointer that gave the Nets their biggest lead at 94-83 with 1:50 left to play. But Milwaukee ran off an 11-2 run down the stretch and pulled to 96-94 with 6.9 seconds left on two layup by Brandon Jennings.

Gerald Wallace inbounded to Williams, but Jennings was draped over the point guard's right side. The contact shook the ball loose and it appeared to hit Williams' foot before rolling out of bounds. After review, the Nets had possession. Williams was fouled and made one of two free throws to make it 97-94 with 3.4 seconds left.

Williams then fouled Ellis on a hurried 3.

"He turned and lost his footing and kind of flopped," Williams said. "If I pushed him, I definitely didn't push enough for him to go flying out of bounds like that. It worked out in the end. Let's say I planned it. I knew he was going to miss the free throws."

Ellis missed the first two shots, and intentionally missed the third.

"Every game isn't going to be pretty," Williams said. "You are going to have these grind it out games. We got down and we are able to fight back and keep our composure and get a win."

Jennings scored 31 points and had 11 assists, Ersan Ilyasova had 12 rebounds and Larry Sanders had 12 points, 13 rebounds and five blocked shots for Milwaukee.

It was the Nets' fourth consecutive win, all against teams currently holding a playoff spot. With the Knicks losing to Indiana 125-91, the Nets pulled to within one game of first-place New York in the Atlantic Division.

Sanders returned to the Bucks' starting lineup Tuesday after missing four games with a lower back contusion.

"Last night, we didn't have the lead. We had to fight back," Sanders said of the Nets' victory Tuesday night, when Joe Johnson hit a jumper just before time expired to win it in Brooklyn. Johnson also forced the extra session with a tying 3-pointer as regulation wound down.

"Tonight, I think fatigue caught up to us a little bit, but I'm not going to blame it on that," Sanders said.

C.J. Watson had 17 off the bench for Brooklyn. Andray Blatche scored 12 points and had 12 rebounds for the Nets

Williams, who had 19 points and nine assists Tuesday after sitting out the previous two games with inflammation in his ankles, played 33 minutes. He had eight assist and one steal.

The Nets took advantage of the Bucks' inability to hit shots in the fourth quarter with a 19-5 run.

Williams' 3 at 1:50 gave Brooklyn its biggest lead at 94-83 lead. The Bucks held the Nets scoreless for the next 1:35.

The Nets used a 16-1 run spanning the third and fourth quarters and took the lead 77-76 on Blatche's layup with 10:11 left to play and MarShon Brooks made two free throws to push the lead to 79-76.

Ellis that stopped a Bucks' scoring drought that lasted a little less than seven minutes. He made one of two free throws with 8:11 to go, but Johnson hit a jumper to put Brooklyn up by four.

The Nets trailed 54-42 at the half, but used a 7-0 run in the third quarter to pull to 66-61 with 4:25 left. Williams made a 3 and Watson a layup before Wallace's dunk off a miss by Jennings, who was nine of 10 until Brook Lopez blocked his shot.

The Bucks were 21 of 34 (61.8 percent) the first half while the Nets struggled and made 15 of 46 shots (32.6 percent).

Jennings had 18 points before the break, making all seven of his shots, and seven assists. Ersan Ilyasova had 10 points and seven of Milwaukee's 23 rebounds.

NOTES: Williams said that he would be getting cortisone shots Thursday in his ailing ankles. ... Sanders extended his NBA lead to 19 games with four or more blocks in a game. ... Before the tip-off, there was a moment of silence in remembrance of the owner of the Los Angeles Lakers, Jerry Buss, who died Monday. ... The Nets improved to (19-8) under interim coach Carlesimo, the second-best start under any of their previous 21 coaches. Lawrence Frank's team started 19-6 in 2003-04. ... The Nets are 8-0 when Watson scores 11 or more points. ... The Nets have won consecutive games against the Bucks for the first time since the 2008-09 season.