A teenager had both of his legs severed when he was struck by a train while celebrating his 18th birthday on the NSW mid north coast, police say.

But police and paramedics who arrived to try to help the seriously injured teenager as he lay stuck under the train in Taree were pelted with rocks and verbally abused in the early hours of Sunday morning, police say.

Police officers and the train driver initially had to take refuge in the driver's cabin before police reinforcements arrived to protect them from the crowd, which had gathered near the railway crossing on Bushland Drive about 4.30am on Sunday.

An ambulance windscreen was also smashed and paramedics were "blocked, pushed and verbally abused" during their initial attempts to treat the teenager, police said.