To some extent the role of captain of the port is analogous to that of a harbourmaster.
In the Royal Navy, the captain of the port was the officer, usually with the rank of captain, responsible for the day-to-day running of a Naval Dockyard under the authority of the admiral-superintendent. He usually also held the position of Queen's or King's harbourmaster and was directly responsible for the captain's department, which among other things operated the yard craft.
From the 1650s until the mid-nineteenth century the position was known as master attendant, and ranked immediately below that of Navy Commissioner. Occupants of the office were required to be "skilful in all affairs requisite in the looking after, equipping and setting out of State ships", for which they initially received an annual wage of between £90 and £100 plus accommodation. The office was often combined with that of harbourmaster, and existed until the second half of the 19th century, when occupants (in common with Royal Naval masters) began to be commissioned with the rank of staff captain. From the early twentieth century the equivalent appointment became staff captain (dockyard), then captain of the dockyard, and finally captain of the port from 1969.
In the United States, the captain of the port is usually the United States Coast Guard sector commander. Captain of the port duties involve enforcing within their respective areas port safety and security and marine environmental protection regulations, including regulations for the protection and security of vessels, harbors, and waterfront facilities; anchorages; security zones; safety zones; regulated navigation areas; deepwater ports; water pollution; and ports and waterways safety.