The 31-year-old opener, who has appeared in nine Test matches, left Taunton by mutual agreement last month in order to relocate to London.
Compton, who previously played for Middlesex between 2001 and 2009, has signed a three-year deal at Lord's.
"The time feels right to return home. Hopefully I can come back and reproduce my best cricket here," he said.
South Africa-born Compton made his England debut in November 2012 after scoring 1,494 first-class runs for Somerset that summer, but he has not featured for the national team since being dropped for the home Ashes series against Australia in 2013.
Following five years at Taunton, he described his return to Middlesex as an "exciting challenge" and has targeted a return to the England set-up.
"Leaving Lord's to play for Somerset was, at the time, a step in my development I felt I needed to make," he said.
"Whilst at Somerset I grew as a player and a person. I also fulfilled the dream of representing England, which is something I am determined to do again."
The grandson of England great Denis Compton, he has scored 9,163 first-class runs at an average of 43.84 since making his debut in 2004, including 22 centuries.
Middlesex managing director of cricket Angus Fraser said the right-hander had "a lot to offer" the club on and off the pitch.
"Players of Nick's ability do not become available very often and when we were made aware of his desire to move back to London we immediately moved," he added.
"With Chris Rogers hopefully playing for Australia next summer we needed to find a high quality top order batsman and in Nick we have secured the services of one.
"It will be great to see him once again wearing a Middlesex cap and sweater."
Middlesex have re-signed England Test batsman Nick Compton following his departure from Somerset.