The United States gained Puerto Rico as a result of the Spanish-American war.
This war happened in 1898 after the USS Maine was destroyed in Cuba, and after America acquired some of Spanish territories in South America. The primary incentive for the war was the fact that Cuba wanted its independence from Spain, which America took advantage of to take control over Cuba. In the aftermath of this war, America acquired several states from Spain, including Cuba, the Philippines, Puerto Rico, and part of Guam.