Major League Baseball and the players' union made the announcement Friday. Pittsburgh and Miami will meet on May 30-31 at Marlins Park.
The union had asked commissioner Rob Manfred to relocate the games after several players expressed fears about getting and possibly transmitting the Zika virus.
The U.S. Centers for Disease Control and Prevention has said Zika can cause a birth defect called microcephaly, in which infants are born with unusually small heads. The virus is most often spread by mosquito bites, but it also can be spread through sexual intercourse.
"You trust the process that the union and the league is going to do what's best for everyone and make sure they take care of everyone," Marlins manager Don Mattingly said before Friday night's game against Philadelphia.
The CDC had spoken to players and staff from the Pirates and Marlins about the potential risks.
Cardinals catcher Yadier Molina, who's from the island of Puerto Rico, tweeted about the announcement Friday.
go visit my beautiful Puerto Rico !!— Yadier Molina (@Yadimolina04) May 6, 2016
Still dont understand why MLB cancel the games down in PR! Wow!
In a release, MLB and the union said "players who objected to the trip because of their specific family situations should not be forced to travel to Puerto Rico.
"Because too many regulars on both clubs fell into that category, Commissioner Manfred had no choice but to relocate the games."
The Pirates and Marlins were originally scheduled to play the series in Miami when the original draft of the schedule was made last year. On Nov. 19, 2015, MLB said the games would be played in Puerto Rico, the homeland of Pirates Hall of Famer Roberto Clemente and many other big leaguers.
Clemente's son Luis expressed his frustration over the cancellation to the Pittsburgh Tribune-Review.
"We are very disillusioned over the decision," Luis Clemente told the newspaper Friday. "We need to have a conversation to fully understand what happened."
In the past, MLB teams have played several regular-season games at Hiram Bithorn Stadium in San Juan. MLB said it hoped to play again in Puerto Rico sometime in the future.
"People were really looking forward to the series and to have the opportunity to attend Major League Baseball games in Puerto Rico," Yankees outfielder Carlos Beltran, another Puerto Rico native, told ESPN's Marly Rivera. "We all know that Puerto Rico is going through a very difficult time and this is basically just another low blow for the island."
Puerto Rico has had 785 confirmed Zika cases, including its first death from the virus.
"It's ironic that athletes are willing to go to Brazil to the Olympics and don't want to come to Puerto Rico," Puerto Rico governor Alejandro Garcia Padilla recently told local newspaper El Nuevo Dia.
Brazil is at the center of the Zika outbreak, putting Olympic host Rio de Janeiro in the spotlight with 10,500 athletes and up to 500,000 foreign tourists expected for South America's first games.
Nothing has been canceled at the Games, and nearly all athletes still plan to compete.
On Wednesday, Garcia Padilla said Miami and Tampa also have Zika cases, and suggested players who asked for the games to be moved "are not very smart."
The decision to shift the games from Puerto Rico is another blow to an island mired in recession and unable to pay $72 billion in public debt. The U.S. territory has been suffering through more than a decade of economic decline since Congress phased out tax cuts that made the island a center for pharmaceutical and medical equipment manufacturing.
Puerto Rico missed nearly $370 million on a bond payment Monday, and officials warned of worse to come without relief from Congress. Garcia Padilla said he had no choice but to suspend the debt payment to avoid cutting essential public services such as schools and medical care.
MLB and the union will make contributions to help combat Zika in Puerto Rico. Also: Manfred and several former players plan to hold youth clinics and events on the island later this month.
Information from The Associated Press was used in this report.