NORTHAMPTON -- The days when rail-trail cyclists would illegally carry their bicycles over the former Pan Am railroad tracks when traveling from Amherst to Northampton are over.

Thursday morning, officials cut the ribbon on a $4.4 million two-lane cast concrete tunnel underneath the tracks, which are now owned by the Massachusetts Department of Transportation and actively used by freight lines and the high-speed Amtrak Vermonter.

The bike tunnel connects the Norwottuck Rail Trail -- which originates in Belchertown, goes through Amherst and Hadley, and crosses the Connecticut River -- with rail trail networks in Northampton and Easthampton. The underpass actually opened in November after many years of planning.

"You've got a great trail system on this side of the tracks, and you've got a great trail system on that side of the tracks," said Massachusetts Department of Transportation Secretary Stephanie Pollock, who spoke of the importance of "making connections."

She said the east-west bike link may have a "small footprint," but the underpass will have a large benefit -- allowing commuters, students, residents, and recreational cyclists to travel across the breadth of the Pioneer Valley without risking their lives.

"How many of you here have ever carried your bike over the railroad tracks?" asked Pollock, as many in the crowd laughed and raised their hands. "That's why we built this. It's dangerous. Now that we've built this nice, safe connection for everybody, don't go up there anymore."

Pollock joined Northampton Mayor David Narkewicz, members of the cycling community, and state and regional officials in celebrating the milestone.

"We're really happy to be here today to celebrate the opening of this underpass," said MassDOT highway administrator Jonathan Gulliver.

It was a 43 years ago that the idea of a bicycle tunnel under the Connecticut River Rail Line was first floated, said Mayor David Narkewicz. Specifications were developed 25 years ago, he said. Federal money was announced in 2010.

The tunnel is a final detail in the Knowledge Corridor rail project, built with stimulus funds released under the Obama administration. The project upgraded tracks and other facilities to restore intercity passenger rail service between Springfield and White River Junction.

The bike underpass was substantially completed last year, but not officially open to the public until Nov. 9. A fence and "no trespassing" sign did little to deter cyclists from sneaking through the tunnel anyway.

The Massachusetts Bay Transportation Authority managed the tunnel's design and construction. It wasn't easy, said project manager John Doherty.

"During the entire course of the project, we had to have the track active," he said, while citing challenges in the areas of engineering, timing, access, and safety.

Pollack said the Baker administration allocated extra cash to push the tunnel project over the finish line. Baker asked MassDOT to identify capital projects where a state infusion could make a big difference, she said -- and "this project was identified early on."

"Some people might look at this and say, '$4.4 million is an awful lot of money for something that's not very big,'" Pollack said. "But it might not be physically large, but it's a big idea."

She said it's about "finding the gaps in networks, and making strategic investments to fill those gaps."

Children from the Montessori School on Bates Street attended the event. Headmaster Mark Dansereau offered "deep gratitude." He said families and children want to ride their bikes to school, and that the tunnel "allows our community to express its values."

Narkewicz said the underpass represents a "hub" in the region's rail trail network, and that bikeway connections are growing from New Haven and Boston.

The mayor praised Pedal People, the bicycle-powered trash, recycling, and compost pickup service centered in Northampton. The cooperative has a contract with the city to service the downtown area.

"Only in Northampton," quipped Pollack.

Narkewicz gave a nod to Valley Bike Share, about to launch with its fleet of shared bicycles across Amherst, Northampton, Holyoke, Springfield, and South Hadley.

Narkewicz said that automobile use contributes significantly to a person's carbon footprint. "So get out of your cars, get on a bike, and do it safely," he said.