J.R. Smith hit a 3-pointer for the lead with 1:04 left, and the New York Knicks held on to beat the Milwaukee Bucks 111-107 on Wednesday night in a game that could turn out to be critical to both teams' playoff hopes.

Carmelo Anthony had 32 points and 10 rebounds, while Tyson Chandler added 19 points for the Knicks, who took a two-game lead on Milwaukee for the No. 8 seed in the Eastern Conference. Smith had 14 points off the bench.

Monta Ellis had 35 points and Brandon Jennings added 22 for the Bucks, who were coming off a 20-point loss to Oklahoma City at home on Monday.

The Bucks had won two of three games with the Knicks before Wednesday, and a win would have given them a head-to-head tiebreaker edge.

Milwaukee led 88-84 going into the fourth quarter, then started the period with a quick 6-2 run to take a 94-86 lead. Ekpe Udoh, the other player the Bucks obtained in last month's trade for Ellis, scored a pair of inside baskets during the run.

With the Knicks' chances appearing to fade, Anthony drew a technical foul when he slammed the ball on the floor in frustration with 8:53 left in the game. But Jennings missed the foul shot and the Knicks used a scoring spurt to tie it at 99 on a 3-pointer by Smith. New York then took a 101-99 lead on a pair of free throws by Smith with 3:16 left.

Chandler then picked up his fifth foul, and Udoh hit one of two free throws to cut the lead to one.

Anthony then scored on a rebound of his own miss, and Udoh hit a jumper on the other end.

Udoh then came up with a block on Iman Shumpert, Mike Dunleavy Jr. rebounded a miss on the other end and kicked it out to Ellis, who hit a 3-pointer from the top of the key to give the Bucks a 105-103 lead with 1:45 left.

Anthony hit a turnaround jumper at the other end to tie the game.

Luc Richard Mbah a Moute scored on a putback on the other end for Milwaukee, but Smith hit a wide-open 3-pointer with 1:04 left to give the Knicks a 108-107 lead.

After a miss by Dunleavy, Steve Novak — a former Marquette University standout who knows the Bradley Center rims well — hit a pair of free throws for a 110-107 Knicks lead with 19.4 left.

Brandon Jennings missed a 3-pointer that would have tied the game, and Shumpert was fouled and hit one of two free throws for a four-point lead with 9 seconds left.

The Knicks took advantage of woeful interior defense by the Bucks early on, hitting 11 of their first 12 shots — a lot of them coming on layups. Of the Knicks' first 30 points of the game, 26 of them came in the paint.

New York shot 77.3 percent from the field in the first quarter and led 36-27 going into the second, but the Bucks came roaring back with a 15-2 run to take the lead. Backup Bucks forward Larry Sanders had a pair of blocks during the run, helping Milwaukee close off the interior on defense.

The teams went into the third quarter tied at 62.

NOTES: Anthony appeared to tweak his right wrist on a play in the second quarter but stayed in the game. ... It was a short night for Milwaukee center Drew Gooden, who is nursing a sore back and played only 5:02. ... A long jumper by Dunleavy in the first quarter was ruled a 3-pointer after a replay review by officials.