 During most of the colonial period, Costa Rica was the southernmost province of the Captaincy General of Guatemala, nominally part of the Viceroyalty of New Spain.In practice, the captaincy general was a largely autonomous entity within the Spanish Empire.Costa Rica's distance from the capital of the captaincy in Guatemala, its legal prohibition under Spanish law from trade with its southern neighbor Panama, then part of the Viceroyalty of New Granada (i.e.