In addition, the Marlins agreed to a one-year contract to keep right-hander Dustin McGowan, according to the Associated Press.
The 29-year-old Locke had spent his entire big league career with Pittsburgh and was 9-8 with a 5.44 ERA this year in 19 starts and 11 relief appearances, his highest ERA since 2012.
His best season was 2013, when he went 10-7 with a 3.52 ERA in 30 starts, earning a spot on the NL All-Star roster.
Locke gets the same salary he had this year with the Pirates. He became a free agent when Pittsburgh failed to offer a contract by the Dec. 2 deadline.
McGowan, 34, had a 2.82 ERA in his first season with the Marlins, striking out 63 in 67 innings.
The Associated Press contributed to this report.