In 1775, O'Reilly was given command of a major Spanish expedition attacking Algiers. Although this North African campaign was a disaster, the high reputation of O'Reilly was not destroyed, and he continued to serve as captain-general in southern Spain.