Later, Charles III of Spain would seek to solve the problem with the Regency of Algiers, both through military and diplomatic channels. In 1775, he sent an expedition to Algiers which failed. In 1778 a negotiation failed and in 1782, Algiers did not adhere to the treaty between Spain and the Ottoman Empire. Faced with the refusal, Spain sent a new punitive expedition against Algiers in 1783 and then in 1784. In 1785, when another Spanish expedition was being prepared, Algiers decided to agree with the Spanish government, signing a treaty in 1786 that wiped out the corsairs.