The agreed-to deal is for one year at $2.5 million, but could be worth as much as $3.5 million with incentives, said Loretta's agent, Bob Garber.
Craig Biggio has long been entrenched as the starting second baseman for the Astros. But Garber said Loretta, who has also played first, third and shortstop during his career, will play "all over the infield" for Houston.
"We wanted to wait until the second-base market got better. The market is great for everyone but second basemen," Garber said.
Loretta, a 12-year veteran, played for the Boston Red Sox last season, hitting .285 in 155 games. He has previously played for the Brewers, Astros and Padres and has a career .299 average and .987 career fielding percentage.
"This was a unique opportunity to acquire a high-caliber offensive and defensive player late in the free-agent market," Astros general manager Tim Purpura said. "He will play regularly at all infield positions, and his contribution will definitely make us a stronger team in 2007."
Information from The Associated Press was used in this report.