The governor denied that her administration was taking on the federal government, arguing that the Puerto Rican legislation complied with federal law because it prohibits importing or exporting gamecocks. But in nearly the same breath, Ms. Vázquez acknowledged that the law she signed was likely to be challenged.

“Obviously, the final decision belongs to the court,” she said.

Cockfighting has existed in Puerto Rico for some 400 years, since Spanish colonists brought the practice to the island. When Puerto Rico became part of the United States, cockfighting was outlawed. It was legalized again in 1933 and has been regulated ever since, with 71 licensed cockpits across the island of 3.2 million people.

Ms. Vázquez said the industry brought more than $9 million into government coffers during the past year, when more than 67,000 matchups were held.

But cockfighting is often deadly for the birds. Denounced as cruel by critics, it has been banned in all states since 2008. A loophole in federal law kept the prohibition from applying to United States territories and commonwealths until it was closed by the 2018 farm bill, which included a one-year grace period.