A counselor assigned to Starfleet vessels and installations is responsible for the mental well-being of the crew, and is a position usually held by a senior Starfleet officer with training in psychology. As with the Chief medical officer, the ship's counselor has the power to relieve other officers and crew members of duty if he or she feels that their patient is suffering from a condition that may hinder their ability to perform their duties effectively.
At the Captain's discretion, the ship's counselor may be allowed to wear something other than their normal Starfleet uniform while on duty. This was the case with Deanna Troi, the ship's counselor on the USS Enterprise-D. (Deanna elected to wear a uniform permanently after being told to do so by Captain Edward Jellico.)
The USS Voyager was not originally assigned a counselor as its mission was intended only to last a few months. Later, Neelix appointed himself morale officer, a term of his own invention, to take on the responsibilities of a counselor.
According to a early draft of "Relics" (TNG), Counselor Troi explained that the responsibility of a ship's counselor was to take care of the emotional well-being of a ship's crew and guests. Starfleet began assigning counselors to starships in the 2330s, after they realized that the pressures of extended space travel could result in psychological problems that would require professional care.