The deal is for $3.5 million and could be worth up to $9.5 million over two seasons, as first reported by Fansided.com.
Castro, who turns 28 this month, has already spent eight years in the big leagues, most recently with the New York Yankees. He was 5-0 with a 4.03 ERA in 34 appearances last season.
The 6-foot-7 right-hander has averaged more than a strikeout per inning over the past three seasons. The bullpen was a weak spot for Arizona this year and general manager Mike Hazen said upgrading that area -- particularly with power arms -- was a priority.
Castro has a $3.5 million salary for next season, and the deal announced Friday includes a $5 million option for 2024 that will become guaranteed if he has 60 appearances as a pitcher next season and passes an end-of-season physical.
If he has 40 games finished this year and passes his end-of-season physical, he will get a $6 million player option.
Castro can earn up to $2.75 million annually in performance bonuses: $900,000 for games pitched and $1.85 million for games finished.
He would get $50,000 each for 25, 30 and 35 games pitched, $75,000 apiece for 40 and 45, $100,000 apiece for 50 and 55, and $200,000 each for 60 and 65.
Castro would get $100,000 for 25 games finished, $150,000 each for 30 and 35, $200,000 for 40, $250,000 for 45, $300,000 for 50 and $350,000 each for 50, 55 and 60.
Arizona finished 74-88 last season, a 22-win improvement over 2021.
The Associated Press contributed to this report.