The announcement came a day after UCF officially accepted an invitation to join the Big East Conference.
Roof was a member of O'Leary's staff at Georgia Tech from 1995 to 2001, spending his final three years there as defensive coordinator.
O'Leary fired former defensive coordinator John Skladany, linebackers coach Al Seamonson and director of player personnel Albert Boone two days after Knights' season finale. He recently hired Drew Hughes from Alabama to fill the player personnel post, but is still looking for a new linebackers coach.
Roof said he is starting immediately and won't be on the sidelines with Auburn when it takes on Virginia in the Chick-Fil-A Bowl Dec. 31. Auburn coach Gene Chizik said he will handle the defensive coordinator duties during the game.
"Auburn's a wonderful place as well and we had a lot of success,' Roof said. "But at the same time this opportunity came along and it was just too good to pass up for myself and my family."
Roof signed a three-year contract with Auburn earlier this year paying him $500,000 a year, but a young Tigers' defense was 78th in total defense (406 yards per game) and 79th in scoring (29.3 points per game) a year after their national title run.
Chizik, who previously was an assistant at UCF, issued a statement Thursday thanking Roof for his time with the Tigers.
"I'm very appreciative of the passion, energy and work ethic Ted brought to the program every day," Chizik said. "I know that this will be a great opportunity for Ted to be reunited with his mentor in George O'Leary and we wish him and his family nothing but the best at UCF."
Roof takes over a UCF defense that led Conference USA in several major defensive categories, but had trouble stopping teams late in games during a disappointing 5-7 season.
O'Leary said he interviewed several other candidates, but Roof was his initial target in the beginning of the search. He said their previous familiarity and his coaching philosophy are a good match to help get the defense back to performing to his expectations.
Information from the Associated Press was used in this report.