Terms were not disclosed, but a source familiar with the deal told ESPN's Jeff Passan that the deal is worth $14 million.
The contract also includes a mutual option for the 2024 season.
Melancon, who will turn 37 in March, led Major League Baseball last season with 39 saves for the San Diego Padres.
Overall, he went 4-3 with a 2.33 ERA in 64⅔ innings pitched for San Diego in his first season with the franchise.
He has 244 saves in his career, fourth among active pitchers.
Arizona didn't have many leads to protect last season during the ninth inning. The entire pitching staff combined for 22 saves. Melancon said he believes that will change in a hurry.
The veteran pitched against the Diamondbacks -- who were division rivals with the Padres in the NL West -- eight times last season and said it was a tough group to face.
"It's tough to see it when you just look at paper, but when you're facing these guys and trying to get them out, it's a different story,'' Melancon said. "I got to see it first hand. I'm very confident in this group.''
Melancon will almost certainly be the team's closer.
"He's a proven back end bullpen guy,'' Arizona general manager Mike Hazen said. "We talked at the beginning of the offseason about wanting to rebuild our pen. It was a major issue for us last year. ... Getting a guy in this spot was important for us.''
The four-time All-Star is 34-30 with a 2.79 ERA over 13 major league seasons for the Pittsburgh Pirates, San Francisco Giants, Atlanta Braves, New York Yankees, Houston Astros, Boston Red Sox, Washington Nationals and Padres.
The Associated Press contributed to this report.