The archipelago voted to remain French with 53.26% of votes, according to final results reported by AFP news agency. Turnout - at 85.6% - was high.
In a similar vote two years ago, the margin was slightly wider, with 56.7% voting to stay French.
New Caledonia has been a French territory for nearly 170 years.
French President Emmanuel Macron welcomed the result as a "sign of confidence in the republic", adding he also felt "humility" in view of the results.