Nathan Bastian had a goal and an assist, and Vitek Vanecek made 15 saves for New Jersey.
Chris Kreider and Alexis Lafreniere each scored short-handed, and Igor Shesterkin allowed three goals on 25 shots in two periods for New York. Olof Lindbom made nine saves in the third.
Kreider gave the Rangers a 1-0 lead at 5:46 of the first period on a 2-on-1 with Adam Fox.
Miles Wood tied it 1-1 at 16:01 after receiving a stretch pass by Hamilton, who scored 41 seconds later to make it 2-1.
Bastian pushed the lead to 3-1 at 14:56 of the second period before Tomas Tatar made it 4-1 at 6:02 of the third on a backhand from the right circle.
Lafreniere brought the Rangers to within 4-2 at 13:08, but Erik Haula scored into an empty net at 17:11 for the 5-2 final.
Sammy Blais had four hits in 13:31 in his first game this preseason for the Rangers. The forward, who was acquired in a trade with the St. Louis Blues for forward Pavel Buchnevich on July 23, 2021, played 14 games last season before tearing his ACL in his right knee on Nov. 14.