The next manager of the Red Sox will come from a division rival, a team source saying late Saturday night there was a deal to bring John Farrell back to Boston.

Farrell will become the 46th manager in team history after spending two seasons as manager of the Toronto Blue Jays. Compensation has yet to be announced, although a team source said that Mike Aviles will be going to Toronto with a player coming back to the Sox.

Farrell, who received a three-year contract, will be introduced at Fenway Park on Monday or Tuesday.

The 50-year-old Farrell was the Red Sox pitching coach from 2007-10 before becoming the manager of the Blue Jays. Farrell was a modest 154-170 in two seasons, but the Red Sox believe he has the skills to lead the team back from its worst season in decades.

Get Sports Headlines in your inbox:

The Globe's most recent sports headlines delivered to your inbox every morning.

The Red Sox were 69-93 under Bobby Valentine, a season marked by underperformance, injuries, and controversy. Valentine’s style did not mesh well with general manager Ben Cherington, his coaching staff or with veteran players grown accustomed to the protective ways of former manager Terry Francona.

The Red Sox formally interviewed Padres special assistant Brad Ausmus, Orioles third base coach DeMarlo Hale, Yankees bench coach Tony Pena, and Dodgers third base coach Tim Wallach, and were impressed with all four. But their focus was on Farrell from the beginning of the process.

In addition, Farrell could play a key role in helping the organization better find and develop starting pitchers.

The Red Sox were interested in bringing Farrell back last season after Francona’s acrimonious departure from the organization. But talks with the Blue Jays broke down quickly when they asked for righthander Clay Buchholz in return.

Friends also said that Farrell did not want to leave Toronto after only one season, feeling a sense of loyalty to an organization that gave him a chance to manage.

The Blue Jays had a rough 2012 season, one marked by injuries and their own internal struggles.

In September, veteran infielder Omar Vizquel complained that young players on the roster were poorly prepared, a charge Farrell denied.

Farrell also had to deal with the three-game suspension of infielder Yunel Escobar, who was punished in September after writing a homophobic slur on his eye black in Spanish.

As it became evident Valentine would be fired, Farrell was asked repeatedly about the idea of returning to Boston. He consistently said he was committed to Toronto, but never denied interest in the Red Sox.

On Sept. 7, before a game at Fenway Park, Farrell spoke warmly about his days with the Red Sox and the people with whom he worked.

“Not only are they professional colleagues, on some level they became personal friends, and we had success,” Farrell said. “We shared a lot of challenges along the way.”

Farrell was with the Red Sox from November 2006 until Oct. 25, 2010. The Red Sox had a 4.11 earned run average during his four seasons, the third-best in the American League. The Sox were in the postseason in three of those seasons.

Farrell was instrumental in the development of Buchholz, Jon Lester, and Daniel Bard. He also meshed well with position players such as Dustin Pedroia and David Ortiz.

“It would be cool for him to get back and pick up where he left off with us,” Buchholz said in September. “I think everyone liked him when he was here. He was always upfront about everything; he was all business. He was an easy guy to talk to if you needed help in some category of the game.”

Farrell attended Oklahoma State, playing four seasons there. He was All-Big Eight as a senior and was a second-round draft choice by the Indians in 1984.

Farrell was 36-46 with a 4.56 ERA in parts of eight seasons with the Indians, Angels, and Tigers. He retired after the 1996 season and returned to Oklahoma State as an assistant coach and recruiting coordinator.

In five seasons with the Cowboys, Farrell coached 14 pitchers who were drafted or signed by major league teams.

Farrell returned to the Indians in November 2001 as director of player development. He was responsible for the team’s minor league affiliates and Latin American programs. Farrell also supervised signing minor league free agents and assisted general manager Mark Shapiro in major league moves.

Farrell was born in Monmouth, N.J. He and his wife, Sue, have three sons: Jeremy, Shane, and Luke. Jeremy Farrell is an infielder in the Pittsburgh Pirates system.