Lavin, 57, replaces Sam Scholl, who was fired March 6 after the Toreros went 15-16 in a third straight losing season. San Diego has had just four winning seasons and one NCAA tournament appearance under three coaches since Brad Holland was fired after going 18-14 in 2006-07.
Athletic director Bill McGillis said Lavin had been a candidate since the beginning of the monthlong search process.
"I just think it's a great alignment. I think under his leadership we have a chance to catapult to new heights," said McGillis, who had dinner with Lavin near campus on Wednesday night.
Lavin was 145-78 at UCLA in seven seasons from 1996 to 2003. He took the Bruins to the Elite Eight in his first season and made four other Sweet 16 appearances. He was fired after UCLA went 10-19 in 2002-03, the only season he didn't get the Bruins into the NCAAs.
He was 92-72 at St. John's from 2010 to '15, with two NCAA tournament berths and two NIT appearances. Lavin left St. John's in 2015 after going 21-12. That season ended with a 76-64 loss to San Diego State in the first round of the NCAA tournament.
Lavin has worked for several seasons as a college basketball analyst on television.
"I considered a lot of outstanding coaches but in the end I just felt that he was the best fit for elevating the level of success on the court," McGillis said.
Lavin updated his Twitter bio with "@USDMBB Head Coach" at one point Wednesday evening before deleting that. Shortly after McGillis tweeted confirmation of the hiring, Lavin restored that line.
"I think I told him his Twitter account got hacked," McGillis joked. "He just decided to subtly share the good news before the rest of us."