Royal Navy vessels were deployed in response to the “foolish” incident in the UK territory.
A Spanish warship with its guns manned ordered commercial ships to leave British Gibraltar waters, the territory’s government said.
Royal Navy ships were deployed in response to the incident on Sunday.
The Spanish warship’s crew can be heard in an audio recording of a radio exchange telling ships anchored at Gibraltar to “leave Spanish territorial waters”.
Commercial boats which were told to move were ordered to remain by the Gibraltar Port Authority.
The actions of the Spanish navy were branded “foolish” by a spokesman for Her Majesty’s Government of Gibraltar.
The spokesman added: “There is only nuisance value to these foolish games being played by those who don’t accept unimpeachable British sovereignty over the waters around Gibraltar, as recognised by the whole world in the United Nations Convention on the Law of the Sea.
“This probably accounts for the state of extremism of some parts of the Spanish political spectrum these days.”
The warship was accused by the government of trying to take “executive action” against the commercial boats, which were anchored on the eastern side of the Rock.
A crew member is heard in the recording asking the Spanish ship “to verify you are referring to our ship” because they are anchored in Gibraltar.
He said: “We are not adrift, we are at anchor now.”
He is then told again to leave Spanish waters.
A statement released by the Gibraltar government said: “The Royal Navy deployed a launch and a rigid-hulled inflatable boat to the scene.
“After being challenged by the Royal Navy, the Spanish warship sailed slowly along the Gibraltar coast with its weapons uncovered and manned.”
The Gibraltar government “is verifying every aspect of the incident in order to ensure that appropriate action is taking as soon as possible”.
Speaking in the House of Commons on Monday in response to the incident, Defence Secretary Gavin Williamson vowed the UK government “will always be there to defend our sovereign interest and defend Britain’s national interests”