Media playback is not supported on this device
It is the 51-year-old's first job since he was sacked as United manager in April after a 10-month spell in charge.
Moyes replaces Jagoba Arrasate, who was dismissed by Sociedad after a poor run of form which currently sees them lie 15th in La Liga.
The Scot has signed a contract to June 2016 and will take charge for the first time at Deportivo on 22 November.
Sociedad announced the appointment late on Monday in a statement on their website.
"Real Sociedad have reached an agreement with David Moyes," it read.
"Details about the official presentation of Real Sociedad's new coach and who will form part of his technical team will be published tomorrow [Tuesday] morning."
Moyes recently told BBC Football Focus he was ready to return to management but would wait for the "right job".
In the interview, he did not rule out a job in Europe.
"It is something that we don't report enough - British managers outside the shores," he said.
"It will actually help the development of coaches where you can come back and give a bit back to them - tell them the experience you have had working in Spain, Italy, Germany or wherever it may be."
Former Preston and Everton boss Moyes took over at Manchester United as a successor to Sir Alex Ferguson, who had an illustrious 26 years in charge at Old Trafford.
However, Moyes was sacked with United lying seventh in the Premier League four games from the end of last season.
He faced Basque side Sociedad as United manager, recording a 1-0 win at Old Trafford and a 0-0 draw in Spain during the Champions League group phase.
Moyes becomes the fourth British manager of the club.
Harry Lowe was in charge for five years from 1930, while John Toshack had three spells in charge, with the last coming to an end in 2002.
Toshack's fellow Welshman Chris Coleman lasted less than seven months following his appointment in July 2007.
Although they are 15th in La Liga, Sociedad have already beaten Real Madrid this season and recorded their second win of the campaign on Sunday when they overcame champions Atletico Madrid.
Former Manchester United boss David Moyes has been named as the new manager of Spanish club Real Sociedad.