The 21-year-old striker has agreed a four-year contract to become big-spending Boro's seventh new signing this summer.
Fletcher joined West Ham from Manchester United last year but started just two Premier League matches, and has been pushed further down the pecking order by the arrival of Javier Hernandez.
Hammers manager Slaven Bilic told the club website: "We got a fantastic offer for Ashley and ideally I wanted to help him with a different kind of scenario, but at the end of the day the offer was so good for the club and for him personally.
"I spoke to him on Wednesday night and I told him to be proud of the step that he made since coming to West Ham last year to being a player that a lot of clubs from the Championship are asking for.
"To make such a big step is a big bonus for him and a big thing for him. He's very young, very promising, a great lad and a great trainer, so he can improve a lot."
Fletcher is the second player to sign for Middlesbrough from West Ham in the last seven days, joining goalkeeper Darren Randolph at the Riverside.
Relegated Boro have also brought in Britt Assombalonga - for a club-record fee of Â£15million - Martin Braithwaite, Cyrus Christie and Jonny Howson on permanent deals, and Connor Roberts on loan from Swansea, as they bid to bounce back to the Premier League at the first attempt.