The Twins’ expected midseason roster makeover started at the top Thursday: They traded their All-Star.

Eduardo Nunez, the Twins’ lone representative in San Diego earlier this month, was dealt to the San Francisco Giants immediately after Minnesota’s 6-2 victory over Baltimore. In return, the Twins received Adalberto Mejia, a 23-year-old lefthanded starting pitcher who was recently rated among baseball’s top 100 prospects by Baseball America.

“We think he’s fairly close to the big leagues,” interim General Manager Rob Antony said after consummating his first transaction since replacing Terry Ryan last week. “I don’t know if he’ll pitch up here this year, but we believe he’s definitely a candidate to be in our rotation next season.”

Jorge Polanco, one of the Twins’ top infield prospects who has already spent three separate stints on the big-league roster this season, has been recalled from Class AAA Rochester to replace Nunez.

It’s a bittersweet departure for Nunez, whose career blossomed in Minnesota from a utility player begging for at-bats to an everyday shortstop ranked among the AL’s best. “The Twins are a great organization to play [for]. Great people,” said Nunez, who was informed of the deal after going 0-for-4 in his Twins farewell. “It made me feel like home. It made me feel like I was here for [longer] than I was. It’s tough.”

Nunez barely played during the season’s first two weeks, and was ticketed for another season playing part-time at three infield positions. But after collecting nine hits in his first three starts of the season, Nunez suddenly found himself in the lineup every day for the first time in his seven-year career. He batted .296 with 12 home runs and a league-leading 27 stolen bases, and was selected to the All-Star team.

“He’s certainly capitalized” on his opportunity to play, Twins manager Paul Molitor said. “I’m happy for him. It’s an opportunity to go out there and contribute to a team that’s trying to set its sights fairly high.”

The Twins set their asking price high, too, and “some people might have been scared off by that,” Antony said. But six different clubs contacted him about acquiring Nunez, and the Giants’ offer of Mejia was the most intriguing.

“He’s got a three-pitch mix. He’s got a big, durable body, so we just think he profiles well,” Antony said. “He’s pretty much what we were looking for.”

Mejia, ranked fifth among Giants prospects by Baseball America, began the season at Class AA Richmond. When he posted a 1.94 ERA in his first 11 starts, the 6-3 lefthander was promoted to Class AAA Sacramento, where he is 4-1 with a 4.20 ERA. Mejia features a 93-mph fastball, along with a changeup and slider. Mejia, who served a 50-game suspension in 2015 after testing positive for a banned stimulant, will be assigned to Rochester.

Antony said he is continuing to negotiate with other teams ahead of Monday’s 3 p.m. trade deadline, mostly with the same goal as the Nunez trade. “We need to increase our pitching depth,” said Antony, who acquired Nunez from the Yankees, in exchange for lefthander Miguel Sulbaran, early in the 2014 season while filling in during Ryan’s cancer treatments. “I’d like to get some guys who are at the higher levels, but if we have a chance to get somebody with a high ceiling in [Class] A or lower in the minor leagues, we’re not afraid to do that as well.”

Moving Nunez likely opens the shortstop position for Eduardo Escobar again, though Polanco and Danny Santana could earn playing time there as well. “It still might be a challenge [for Polanco] to get at-bats, but he’s the right guy to bring up. When we need somebody, he can come off the bench,” Antony said of the 23-year-old Dominican, who is a career .262 hitter in 22 big-league games. Polanco was batting .271 with six triples and nine homers at Rochester this season.

“He has the ability to play short,” Antony said, “though we believe his best positions might be second and third.”