The Spanish troops will join the European Union force sent to protect ships against hijackings and attacks by Somali pirates .