The deal for Pearson, 24, who scored nine goals in 51 appearances in all competitions last season, is a record for an Accrington sale.
The versatile defender is Barnsley's 11th summer signing ahead of their Championship season-opener on Saturday.
"Matty has some exceptional qualities that we feel we can work with and make better," boss Paul Heckingbottom said.
Pearson began his career with Blackburn Rovers and played for Rochdale and Halifax Town before joining Stanley in May 2015, going on to make 103 appearances.
Barnsley begin their Championship campaign at Bristol City on Saturday.
Find all the latest football transfers on our dedicated page.
Barnsley have signed defender Matty Pearson from Accrington Stanley on a three-year deal for an undisclosed fee.