Kemba Walker will be headed to the Celtics to replace Brooklyn-bound Kyrie Irving after agreeing to a four-year, $141 max contract in a three-way, sign-and-trade that saw Terry Rozier head to the Hornets after agreeing on a three-year, fully guaranteed $58 million deal. Chuck Burton/Associated Press/File/Associated Press

The Celtics’ frustrating season was followed by a rough start to the summer. They were unable to acquire Anthony Davis, and then they received word that former All-Stars Kyrie Irving and Al Horford intended to sign elsewhere.

It was enough to make the franchise wobble and even ponder whether it was time to pivot to a full youth movement. But on Sunday, the Celtics struck back.

The team agreed to a four-year, $141 million max contract with Kemba Walker, the Hornets’ three-time All-Star point guard, a league source confirmed.

“When you think of the Celtics, you think of championships and winning,” Walker said during an appearance on ESPN’s “SportsCenter” on Sunday night. “And that’s what I’m about. I’m about competing for championships and winning . . . I just felt like Boston was the best fit for me to try and accomplish those kinds of goals.”

Walker will likely technically come to Boston via a trade. A league source confirmed Terry Rozier has agreed to a three-year, $58 million deal with Charlotte and that the two will ultimately switch sides via a sign-and-trade.

The Hornets are over the cap and unable to sign Rozier to a deal this size outright. The Celtics agreed to the sign-and-trade to keep other options open, according to a league source. Boston could potentially turn it into a three-team, sign-and-trade involving Horford or Irving, who agreed to deals with the 76ers and Nets, respectively, on Sunday, in order to free the $9.2 million mid-level exception that they could use on other players. But even if that does not happen, a source said, Boston will receive compensation in some form from Charlotte.

Late Sunday night, ESPN reported Horford had agreed to a four-year, $109 million contract with the 76ers, giving a major boost to one of the Celtics’ top rivals after it lost Jimmy Butler to the Heat. Irving’s departure to sign with the Nets, where he will team up with Kevin Durant, was more expected.

For the Celtics, though, the most important development on this busy day was that Walker is bound for Boston.

Last season, he averaged 25.6 points, 5.9 assists, and 4.4 rebounds per game for Charlotte and he received third-team All-NBA recognition. He publicly stated several times that he hoped to return to the Hornets, who were in position to offer him a five-year, $221 million super-max contract — or even just a five-year $190 million max contract — but they never came close. According to a league source, it became obvious earlier this week that the sides were heading in different directions.

Now the Celtics will plug in one of the few point guards capable of at least mimicking Irving’s production. And around the league there is already considerable buzz among those who are intrigued to see how Walker will thrive when his strengths are unlocked by Boston coach Brad Stevens.

Irving’s tenure in Boston, meanwhile, has officially come to an awkward end. In August 2017, the Celtics acquired him from the Cavaliers and had big dreams he could become their franchise’s cornerstone after helping Cleveland to the Finals in three consecutive seasons.

Knee surgery sidelined Irving for the duration of the 2018 playoffs. But he returned at the start of this season healthy and eager. At a fan appreciation event in October, he famously stood up from a chair and told thousands of fans he planned to re-sign with the Celtics this summer. He even filmed a Nike commercial in which he spoke of having his number hanging in the TD Garden rafters someday.

Then the Celtics struggled through a disappointing regular season, and midway through the year Irving already began to publicly waver on his earlier stance. When he was asked if his thoughts about sticking with the Celtics had changed, he replied: “Ask me July 1.”

Things did not really get better after that, and Boston was ultimately crushed in the second round of the playoffs by the Bucks. By season’s end, it was clear among most Celtics staffers that Irving’s tenure in Boston was likely over.

But, at that time, there wasn’t much thought about the possibility of replacing one All-Star point guard with another in Walker.

The Walker deal has seemed imminent for days, of course, and the Celtics’ focus will quickly shift toward bolstering their frontcourt. The loss of Horford will be significant.

While so many free agent deals and meetings have become public knowledge this week, his plan remained mostly cloaked in secrecy.

According to a league source, Horford planned to speak with several teams Sunday night and then make a final decision Monday or Tuesday. But that process might have accelerated after Butler’s departure in Philadelphia offered some clarity.

Rozier, meanwhile, cashed in like few expected he would. The Celtics on Saturday tendered a qualifying offer to Rozier, making him a restricted free agent. In order to sign Walker to a four-year, $141 million max contract, they would have needed to rescind Rozier’s qualifying offer or complete a sign-and-trade.

According to a league source, Rozier generated significant interest from the Suns, Knicks, Mavericks, Bulls, Hornets, Clippers, and Magic. In the end, the sign-and-trade with Charlotte has proved to be the best option for all parties.

In extension discussions with the Celtics last year, Rozier’s camp was seeking an annual salary of about $18 million. The Celtics were unwilling to bid that much, though, and talks stalled. Now, however, he will be paid even more.

Last season Rozier averaged 9 points, 3.9 rebounds, and 2.9 assists per game as Irving’s backup. But Charlotte might have been most intrigued by what it saw from Rozier when he had a primary role in place of the injured Irving during the 2018 playoffs.

Rozier averaged 16.5 points, 5.3 rebounds and 5.7 assists, helping guide Boston within one game of the NBA Finals.