Many kingdoms from the kingdom of Leon, like Castille, became Spain, but not the county of Portugal. Both countries were even ruled by the same king, Filipe II. How was it possible?
Check out the FAQ.