Officers seized around 2.5 tonnes of hashish from a house in a rural area near the port of Algeciras on Wednesday night after a tense standoff with suspected traffickers who had barricaded themselves inside, police said in a statement.
The police were targeted by "at least six shots from inside the house", some of which only narrowly missed officers, it added.
The four suspects inside the house gave themselves up after two hours of negotiation and were arrested.
Cuatro agentes de la @policia fueron tiroteados desde una vivienda de Algeciras cuando patrullaban. Tras pedir refuerzos y actuar un negociador, los agresores se entregaron, fueron detenidos y les intervinieron 2.500 kilos de hachís, dos pistolas y dos escopetas. pic.twitter.com/b5BwhaTyYD— Juan Ignacio Zoido (@zoidoJI) April 5, 2018
Earlier on Wednesday, police seized more than six tonnes of hashish hidden in the basement of a house in the poverty stricken town of La Linea de la Concepcion on the border with Gibraltar, the disputed British territory on Spain's southern tip.
The entrance to the basement was hidden by the floor of a shower. A video released by police showed how the shower's floor could easily be opened by a hydraulic system activated by a remote control.
Ocultaban 6.000 kilos de hachís en 172 fardos en una nave de La Línea dentro de un zulo al que se accedía por un sistema hidráulico. La @policia los ha intervenido y ha detenido a una persona. pic.twitter.com/MUJBuSCcoG— Juan Ignacio Zoido (@zoidoJI) April 5, 2018
Police arrested one man during the operation, while several others managed to flee.
Interior Minister Juan Ignacio Zoido in February vowed to send more police to Cadiz after around 20 people stormed a hospital in La Linea and freed a suspected narco who was under police guard.
In other cases traffickers have openly defied security forces by unloading drugs in broad daylight.
Spain's proximity to Morocco, a key source of cannabis, and its close ties with former colonies in Latin America, a major cocaine producing region, have made it an important gateway for international drug dealers.
According to the interior ministry, 40 percent of all drugs that come to Spain arrive via Cadiz.