The former Australia batsman has signed a four-year deal and will begin duties in January following Windies' tours of India and Bangladesh.
"I have had to make the difficult decision to leave my role of head coach with CWI," Law said. "I will be taking a role with Middlesex which will keep me close to my family, whilst continuing within the cricket family. It is a great privilege to be asked to coach Middlesex and to accept one of the plum jobs in world cricket."
"I have very much enjoyed my time with the West Indies and wish the staff and players every success. There is never a good time to leave but the opportunity to work with Middlesex for four years at the home of cricket was too good to decline."
After brief stints in charge of Sri Lanka and Bangladesh, the 49-year-old took over the Windies' reins in January 2017 and led his team to a memorable Test victory over England at Headingley last summer. Under him, Windies won six of their 15 Tests that included series wins over Bangladesh and Zimbabwe, and a draw against Sri Lanka. Star players like Chris Gayle and Kieron Pollard also returned to the side under Law, after several disagreements with the board.
During his tenure, Windies also went through the Qualifiers to make it to the World Cup 2019.
Law said his time in charge of the Windies had been "very enjoyable"
"I believe we have made tremendous strides forward as a team during the past two years," he said.
His departure means Windies will have a new coach in charge when England visit the Caribbean in January.
Windies director of cricket Jimmy Adams said: "While I regret his leaving and the timing of it, I fully understand his reasons, and along with everyone at Cricket West Indies want to thank him for his dedication and commitment whilst in the role and wish him the very best of luck at Middlesex."
"I am disappointed that Stuart is leaving as I believe that we have made real progress under his leadership," CWI chief executive Johnny Grave said. "I know it was a difficult decision for him and that ultimately the opportunity to work in England, where his family is now based, was a major factor in his decision. We will start the process to appoint a new head coach immediately."
First Published: September 25, 2018, 8:52 AM IST