On October 24, 2015, the Marlins traded Williams to the Pittsburgh Pirates for Richard Mitchell as compensation for the Marlins hiring Jim Benedict from the Pirates as their new vice president of pitching development.[9][10] He spent 2016 with the Indianapolis Indians where he was 9–6 with a 2.53 ERA in twenty games (19 starts).[11]
Williams was promoted to the Major Leagues for September call ups in 2016.[12] In 12+2⁄3 innings pitched for the Pirates, he was 1–1 with a 7.82 ERA.
Williams began 2017 with Pittsburgh as a member of their bullpen.[13] As the season progressed, he was eventually moved into the starting rotation.[14] In 31 games (25 starts) for the Pirates, he compiled a 7–9 record with a 4.07 ERA and 1.31 WHIP. He began 2018 as a member of Pittsburgh's starting rotation. Williams posted a career year, finishing with an ERA of 3.11 in 31 starts, ending the season with a record of 14–10 in 170+2⁄3 innings. In 2019, Williams had a down year, posting a record of 7–9 with a 5.38 ERA over 26 starts and 145+2⁄3 innings.
In 2020 he was 2-8 with a 6.18 ERA.[15] He led the NL in home runs allowed (15).[16] On November 20, 2020, Williams was designated for assignment.[17] He elected free agency on November 28.[18]
Chicago Cubs
On February 5, 2021, Williams signed a one-year, $2.5 million contract with the Chicago Cubs.[19] On May 31, Williams was placed on the injured list after undergoing an emergency appendectomy.[20] In 13 games (12 starts) with the Cubs, Williams went 4–2 with a 5.06 ERA across 58+2⁄3 innings.[21]
New York Mets
On July 30, 2021, Williams was traded to the New York Mets along with Javier Baez and cash considerations in exchange for Pete Crow-Armstrong.[22] He made 10 appearances for the Mets down the stretch, registering a 3.06 ERA with 29 strikeouts in 32.1 innings pitched.
On July 14, 2022, Williams recorded his first career save after tossing three scoreless innings of relief against the Chicago Cubs.[23]
Washington Nationals
On December 10, 2022, Williams signed a two-year, $13 million contract with the Washington Nationals.[24]