NEW YORK — A young humpback whale was released Wednesday in New York Harbor from entangling rope and floats after it was first seen off Cape Cod last October with gillnet gear wrapped around its upper jaw, according to the Center for Coastal Studies in Provincetown.

The center’s marine animal disentanglement team had attempted unsuccessfully in November and December to cut away the gear after the whale was seen in New York Harbor.

Then in June, more reports of the whale came in, so that by the Fourth of July the whale was consistently spotted off Sandy Hook, N.J., and The Narrows in New York City, according to the center.

On Wednesday, a volunteer pilot flew the Center for Coastal Studies team from Provincetown to New Jersey, where they then went to a Coast Guard station at Sandy Hook.

A Coast Guard helicopter located the whale in Raritan Harbor in between shipping lanes, and from a larger vessel the Provincetown team approached the whale in a small inflatable boat and eventually made two cuts in the rope to allow the whale to shed most of the gear, the center said.

“The operation went remarkably well,” said Scott Landry, of the Provincetown center’s team. “The whale was found quickly and we accomplished our goal soon afterward. Now the whale needs time, time to shed the remaining gear as it feeds and time for its immune system to stave off infection.”