Panama was under Spanish rule for almost 300 years (1538–1821), and became part of the Viceroyalty of Peru, along with all other Spanish possessions in South America. From the outset, Panamanian identity was based on a sense of "geographic destiny", and Panamanian fortunes fluctuated with the geopolitical importance of the isthmus. The colonial experience spawned Panamanian nationalism and a racially complex and highly stratified society, the source of internal conflicts that ran counter to the unifying force of nationalism.