Puerto Rico is the rare place whose name belonged to its capital before it belonged to the island. The island's own name was given away in the swap.

Columbus reached the island on 19 November 1493, on his second voyage. He named it San Juan Bautista, after Saint John the Baptist. The people who lived there, the Taino, had their own name for it. Wikipedia reports that it is spelled Boriquen or Borinquen and is "popularly said" to mean "Land of the Valiant Lord," a meaning that is not confirmed. It survives in the demonyms Boricua, borinqueño and borincano.

The Spanish settled in 1508 under Juan Ponce de Leon, the first governor, at a site called Caparra. The settlement then moved to a coastal islet, now Old San Juan, at a site called Puerto Rico, "Rich Port." The dating is messy. Wikipedia says the move came in 1509 and that the new town received its formal name, Ciudad de Puerto Rico de San Juan Bautista, in 1521. EBSCO says Caparra was abandoned in 1521.

For a time the island was San Juan and the harbor town was Puerto Rico. Then the names crossed. Traders and sailors used Puerto Rico for the whole island, while San Juan came to mean the main port and the capital. Wikipedia describes a gradual switch, and says that by 1746 Puerto Rico meant the whole island.

There is a spelling footnote. After the Treaty of Paris in 1898, the United States government and private businesses used the anglicized form Porto Rico. A joint congressional resolution, introduced by Felix Cordova Davila, restored Puerto Rico in 1931.

Today the island is officially the Commonwealth of Puerto Rico, in Spanish the Estado Libre Asociado de Puerto Rico, a name adopted in 1952. Both versions still carry the harbor's name, and the saint's name sits on the city.