Aragon snaps it up from Pisa or Genoa during the Middle Ages -- a period of time in which it was being fought over between the 2 and rule wasn't consolidated.
Actually, OTL, Aragon did just that from Genoa for about a 150 years starting about the turn of the 14th C. Have that take -- then it naturally becomes part of Spain following the union of Castile and Aragon in the 15th C.