As far as I can make out, the Iranian tanker Grace 1 was seized by Gibraltar whilst it was travelling through Gibraltar's territorial waters. See e.g. this article. The stated basis for the seizure was that it was suspected of violating EU sanctions by carrying crude oil to a sanctioned refinery in Syria.
What was the legal basis in international law for this? Even though the ship was in territorial waters, the United Nations Convention on the Law of the Sea specifies that vessels should have either "innocent" or "transit" passage through international straits. There are some restrictions that coastal states can impose on ships, but none of them seem to relate to carrying cargoes in violation of sanctions. As far as I know the sanctions are EU sanctions and so only relevant to domestic law and not international law.
According to Wikipedia, the UK has ratified the UNCLOS whereas Iran has signed but not ratified it. I don't know if this makes any difference.