From Bravo Fleet Infobase
Starfleet Security is the branch of Starfleet responsible for security aboard all Starfleet and some Federation outposts, vessels, and facilities. The agency is responsible for maintaining and enforcing Starfleet Security regulations, procedures and policies on all Starfleet and affiliated facilities, outposts, and vessels. In addition, this agency is responsible for security clearances of all Starfleet/UFP personnel. However on most planets and non-Starfleet facilities, Federation Security, the unified central civilian police force of the Federation, has primary jurisdiction. The agency is also responsible for the security of the Federation President, as well as members of the Federation Council and visiting alien dignitaries.
Federation Security is more akin to local police agencies where Starfleet Security could be considered closer to the Federation's "army" and is equivalent to the Federation's combat army in times of war. During almost every war in the history of the Federation, Starfleet Security has been the primary ground assault force. In recent years, however, this role has been more and more shared with the Starfleet Marine Corps, in and effort to further specialize troops training and skills.
The agency works closely with Starfleet Intelligence and in that manner is responsible for counter-intelligence operations. Starfleet Security also works closely with Starfleet Intelligence to help train Starfleet Security officers in special operations which allow them extra training, skills and abilities than most Starfleet Security officers. These officers are very rarely assigned to starships and outposts like a majority of Starfleet Security personnel, but are instead given special assignments as the need arises in different frontiers of the Federation.