The shooting happened while Jonathan Trevon Smith, Zebulon, was sitting in a parked vehicle at his home at 11:20 p.m.
Smith was transported to the hospital, where police said he was undergoing emergency medical treatment.
Police arrested Alonza Jamal Hunter, 21, of Middlesex, in the shooting. Hunter is being charged with attempted murder, shooting into an occupied vehicle and possession of a firearm by a convicted felon.
Witnesses told officers that Hunter had an altercation with another person shortly before the shooting. They said he was firing a handgun at that person. One round went into the vehicle and hit Smith. Police said he was not the intended victim.