TORONTO -- The John Farrell era is over in Toronto.

The Blue Jays agreed to a deal with the Red Sox on Sunday that released their manager from his contract, allowing him to join Boston.

Toronto acquired infielder Mike Aviles from Boston as part of the transaction for right-handed pitcher David Carpenter.

The Red Sox fired manager Bobby Valentine after a disastrous 2012 season that saw the club finish last in the AL East with a record of 69-93.

Aviles, 31, appeared in 136 games for the Red Sox last season, batting .250 with 13 home runs and 60 RBIs.

Carpenter, 27, was acquired by the Blue Jays from the Houston Astros in July and appeared in three games out of the bullpen. He posted 0-2 record with an 8.07 earned-run average in 33 games with Houston and Toronto in 2012.

Farrell, who was named the 12th manager in Blue Jays history in October 2010, guided the Blue Jays to a 73-89 record this season, good for a fourth-place finish in the American League East division standings. It was a step back from the team's performance in 2011, when Toronto finished 81-81 in Farrell's first season as manager.

Farrell was hired by the Blue Jays after four seasons as a pitching coach with the Boston Red Sox.

He helped instill a more aggressive approach on the basepaths but inconsistent pitching has been an issue since he was hired. Major injuries to several starters wore down the staff in 2012 and ace Ricky Romero had an off-year.

When Boston fired Valentine a day after the regular season ended, reports quickly surfaced that the Red Sox were interested in seeking permission from the Blue Jays to speak to Farrell about the vacancy.

Farrell, who had a signed a three-year deal with Toronto, has a 154-170 career record (.475 winning percentage) as manager.

The native of Monmouth Beach, N.J., has a pitching background. He broke in with the Indians in 1987 and made 109 starts over eight seasons with Cleveland, California and Detroit.

He moved into the coaching ranks in 1997 with Oklahoma State University as an assistant coach and pitching/recruiting co-ordinator. He joined the Indians as director of player development in 2001.

Farrell spent five years with Cleveland before joining the Red Sox as pitching coach in November 2006. Boston won a World Series the next year.