Adrian Wojnarowski believes that with the addition of Gordon Hayward, along with Al Horford and Isaiah Thomas, the Celtics can compete for the Eastern Conference. (0:55)

SALT LAKE CITY -- The Boston Celtics finally got their fireworks -- on the Fourth of July, no less.

Gordon Hayward, the prize of this summer's free-agent class, announced Tuesday that he's going to play for the Celtics, choosing their maximum-contract offer over those from the Utah Jazz, his team since 2010, and the Miami Heat.

The 6-foot-8 small forward has agreed to a four-year, $128 million deal, according to sources. The deal also includes a player option for the final year, sources said. That would allow Hayward to return to free agency with 10 years of NBA service when he could pursue another big-money contract and command a starting salary at 35 percent of the salary cap.

He shared his decision in an article on The Players' Tribune titled "Thank You, Utah."

The 27-year-old Hayward stressed in the 2,000-word article that his comfort and familiarity with his former college coach, Brad Stevens, was a deciding factor in his joining the Celtics. Stevens took over for the Celtics before the 2013-14 season and last season led Boston to 53 wins, the top seed in the Eastern Conference and a conference finals matchup with the Cleveland Cavaliers.

In his second and final year at Butler, Hayward led the Bulldogs to the national championship game, which Butler lost as Hayward's buzzer-beating 3-point attempt failed to go in.

"And that unfinished business [Stevens and Hayward] had together, back in 2010, when I left Butler for the NBA," Hayward wrote, "... as far as I'm concerned, all of these years later, we still have it.

"And that's to win a championship."

In the article, Hayward also addressed reports from earlier in the day Tuesday that stated that he was headed to Boston.

"What's crazy is -- before I even had a chance to make my decision, before I had a chance to sit down and write this, and before I even had a chance to talk about it with the people I love -- I was already reading reports about where I was going," Hayward said. "And I guess that's just the way things work, in 2017. But I'm sorry it had to work out like that."

Free-agent forward Gordon Hayward has waved goodbye to Utah, announcing that he will sign with the Boston Celtics. Jeff Swinger/USA TODAY Sports

Adding Hayward comes with some pain points for Boston. The Celtics must clear the necessary cap space to sign Hayward to a max contract. The Celtics pulled their qualifying offer to floor-stretching big man Kelly Olynyk, sources told ESPN's Adrian Wojnarowski, making Olynyk an unrestricted free agent.

Boston must still renounce veteran free agents Jonas Jerebko, James Young and Gerald Green, then waive the nonguaranteed contract of Jordan Mickey. Boston has another partially nonguaranteed deal in second-year point guard Demetrius Jackson, who could be waived or traded.

The Celtics would still need to move a rotation player -- whether that's Avery Bradley, Jae Crowder, Terry Rozier or Marcus Smart -- in order to generate the needed cap space.

Boston still has young players to provide depth, including the No. 3 picks in the past two drafts in Jaylen Brown (2016) and Jayson Tatum (2017).

When news of Hayward's signing first spread on Tuesday, Celtics All-Star guard Isaiah Thomas posted his familiar "eyes" emoji. His wife, Kayla, posted a video of Thomas dancing around shirtless in a kitchen (though she later deleted it from her Instagram story). Later, Thomas returned to Twitter.

Let's get to it @gordonhayward ☘️⌚️☘️ — Isaiah Thomas (@Isaiah_Thomas) July 4, 2017

Thomas also spoke to ESPN's Wojnarowski saying Hayward is "the type of player we needed to get to the Finals. I'm excited and can't wait to get to work."

Utah now must pivot to fill the hole left by Hayward. The Jazz had been interested in Washington Wizards restricted free-agent small forward Otto Porter Jr., however he has signed a max-contract offer sheet with the Brooklyn Nets worth $106 million over four years, according to multiple reports. The Wizards have indicated that they intend to exercise their right to match any offer to Porter.

Jazz general manager Dennis Lindsey told ESPN's Wojnarowski that he wishes the Hayward family "the very best" and said the team is looking to the future.

"We have a good, young core, and we are going to compete," Lindsey told Wojnarowski.

"Certainly we will miss Gordon and his many contributions to our team, but I always tell our players that 'adversity is opportunity in disguise,'" Jazz coach Quin Snyder said in a statement Wednesday. "This is one of those moments and we need to live those words."

Hayward's decision marks the second consecutive Fourth of July when a high-profile free agent has switched teams. Last year Kevin Durant announced he was leaving the Oklahoma City Thunder for the Golden State Warriors.

It is also the second straight summer that the Celtics have successfully recruited a coveted player on the free-agent market. Last year, Al Horford signed with Boston.

Forty months after Celtics co-owner Wyc Grousbeck first suggested the possibility of Boston lighting up the offseason sky, the Celtics made their biggest free-agent signing in two decades by landing Hayward.

On Twitter, Smart welcomed his new teammate to Boston.

What a celebration on this 4th of July! 🇺🇸☘️@gordonhayward Congrats and welcome! — marcus smart (@smart_MS3) July 5, 2017

Hayward has steadily developed into a franchise-caliber player since the Jazz selected him with the ninth overall pick of the 2010 draft. He has improved his scoring average each season, topping out at 21.9 points per game last season, when he made his first All-Star appearance and led 51-31 Utah to its first playoff appearance since 2012.

He also averaged a career high in rebounds (5.4 per game) last season, dished out 3.5 assists per game and shot 47.1 percent from the floor, his highest mark since his rookie season, when he had a limited role.

Information from ESPN's Chris Haynes and Bobby Marks was used in this report.