The Red Sox also will also get Oakland's competitive balance draft pick while the Athletics received cash considerations in the trade, which bolsters Boston's historically weak outfield defense.

The deal, which took place hours before baseball's 4 p.m. ET non-waiver trade deadline Thursday, marks the end of Lester's storied stint with the Red Sox, who won two World Series championships with the left-hander in their rotation.

Lester, who is scheduled to become a free agent after this season, had publicly stated his desire to remain with the Red Sox. But contract negotiations stalled this past offseason, when Lester reportedly turned down Boston's four-year, $70 million offer.

Red Sox slugger David Ortiz, a teammate of Lester's since 2006, tweeted farewell to the ace pitcher on Thursday morning.

Athletics general manager Billy Beane, who has been the featured subject of a best-selling book and hit movie but has never taken a team to the World Series, left little doubt he is all-in for October by making his second blockbuster trade for a starting pitcher in less than a month.

Beane surrendered his top two prospects to the Chicago Cubs on July 5 in a trade for All-Star Jeff Samardzija and veteran right-hander Jason Hammel. In Lester, Oakland is adding a pitcher with a glittering postseason resume, including a 0.43 career ERA in the World Series.

Beane followed up the Lester deal Thursday morning by trading left-hander Tommy Milone to the Minnesota Twins for outfielder Sam Fuld. Oakland has a 66-41 record, the best in the American League, but leads the second-place Los Angeles Angels by just 2 ½ games in the AL West.

Lester will join a star-studded Athletics rotation that already includes Samardzija, All-Star Scott Kazmir, promising youngster Sonny Gray, Hammel and Jesse Chavez. Hammel, who has struggled badly since joining Oakland, could be in danger of losing his rotation spot with the arrival of Lester.

But when those potential suitors were unable to satisfy their demands, the Red Sox changed course with Oakland and acquired a proven major leaguer in Cespedes, the two-time reigning Home Run Derby champion.

The Red Sox had made finding a run-producing outfielder a priority; over the past month, they had scouted Matt Kemp of the Dodgers, as well. But Kemp was still owed $107 million over the next five years, and Dodgers GM Ned Colletti, in addition to giving Boston a firm no on his top prospects like outfielder Joc Pederson, made it clear he was not moving Kemp.

Cespedes has 17 home runs this season, three more than Boston's outfielders have combined to hit in 2014. He also possesses one of the game's most powerful throwing arms, which in combination with center fielder Jackie Bradley Jr. and right-fielder Shane Victorino, should give the Red Sox a shutdown outfield defense.

At 28, the Cuban-born Cespedes is two years younger than Lester (Cespedes turns 29 on Oct. 18) and will remain under contractual control by the Red Sox for at least another year. Though he has less than three years of major league service time, Cespedes can become a free agent after the 2015 season through a clause in his contract that allows him to avoid salary arbitration and hit free agency.

Cespedes has had a rough month of July -- with a slash line of .198/.221/.352/.573 -- and on-base percentages of .294 and .303 the past two seasons, which do not fit the profile of what the Red Sox usually are seeking. But he should combine with Ortiz and Mike Napoli to give the Red Sox a formidable middle-of-the-order presence -- and one who will regularly visit The Wall. Interestingly, 11 of Cespedes' 17 home runs have come in cavernous Oakland Coliseum.

But in dealing Lester, the Red Sox have paid a high price -- a homegrown staff ace who has proven durable and dependable and was enjoying arguably the best season of his career. He leaves Boston with a 110-63 record in parts of nine seasons with the Red Sox, and was 10-7 with a 2.52 ERA in 2014.

Scratched from a scheduled start Wednesday, Lester was 4-0 with a 1.07 ERA in his last eight starts with the Red Sox, with 54 strikeouts, nine walks and just one home run allowed in 58 2/3 innings.

But the Red Sox decided early on they would not pay the current market value for a premier starting pitcher. Their reported four-year offer in spring training was worth less than half the six-year, $144 million deal Max Scherzer, another impending free agent, turned down from Detroit this spring.

Lester vowed that he would postpone further negotiations and adhered to that pledge, even when Red Sox executives approached his agent, Seth Levinson, and asked to re-open talks.

Because Lester was traded in midseason, any team that signs him this coming offseason will not have to forfeit a draft pick as compensation, which should only increase the market for his services. Even this week, Lester said he would be open to returning to Boston, but there is little reason to believe the Red Sox would pay a premium over what they could have signed him for while he was still in Boston.

In losing Gomes, the Sox are giving up a valuable part-time player who came to symbolize the "Boston Strong" motif adopted by the team in the aftermath of last year's Boston Marathon bombings, posing with biceps flexed on an iconic Sports Illustrated cover last spring.

Gomes hit six pinch home runs while a member of the Red Sox, one fewer than record-holder Ted Williams, and lived up to advanced billing as a platoon player who could hit lefties. He has a slash line of .302/.400/.431/.831 against lefties this season.

In Oakland, Gomes returns to a club where he helped lead a young team to a playoff spot in 2012, and is likely to keep an impressive streak of playing for postseason teams, having been on playoff teams with the Rays, Reds, Red Sox and the Athletics.

He leaves with a fond spot for Boston.

"I'm in a situation right now where I'm getting packaged up with the best pitcher in the game, heading over to the team with the best record in the game," Gomes said in a phone interview with Boston sports radio station WEEI. "I'm a little bit excited there, but at the same time, you talk about a soft spot in my heart, soft spot with some of the relationships I've made in Boston and this chapter, for the time being, has come to an end."