Which of these two appeared first - español or castellano? Yes, the latter! As you may know, in the Middle Ages there was no "Spain" yet. Instead, there were several kingdoms that spread over the Iberian Peninsula. One of them was the Kingdom of Castile, exactly where the Castilian language (castellano) was formed.
The term Spanish / español appeared much later. It is believed that the Castilian language began to be called Spanish in the 18th century, mainly after the War of the Spanish Succession (1701-1714).
With the beginning of the Spanish colonization of the Americas, castellano started appearing in Latin America (starting from 1492 with the first trip of Christopher Columbus). And as the term español wasn't used until the 18th century, Latin American countries borrowed the same language as the one of the colonizers - Castilian. And only after some centuries, several Latin American countries changed their tradition of calling the language "castellano" to "español", while other countries kept on using the term "castellano".
A BIT OF HISTORY