Mejía signed as an international free agent with the San Francisco Giants . He pitched for the Augusta GreenJackets of the Class A South Atlantic League in 2012, and was named the league's Pitcher of the Week for June 18–24.  He pitched for the San Jose Giants of the Class A-Advanced California League in 2013,  where he had a 3.31 earned run average (ERA). The Giants assigned Mejía to the Richmond Flying Squirrels of the Class AA Eastern League in 2014,  and he had a 4.67 ERA. After the season, Minor League Baseball suspended Mejía for the first fifty games of the 2015 season for testing positive for sibutramine , a banned substance.  The Giants added him to their 40-man roster after the 2015 season.  He began the 2016 season with the Sacramento River Cats of the Class AAA Pacific Coast League . 
On July 28, 2016, Mejía was traded to the Minnesota Twins for Eduardo Núñez . The Twins assigned him to the Rochester Red Wings of the Class AAA International League .  The Twins promoted Mejía to the major leagues on August 20.