Terms of the deal weren't disclosed.
Leinart fills an immediate need at Buffalo's injury-depleted quarterback position. The Bills later added quarterback Thaddeus Lewis in a trade that sent linebacker Chris White to Detroit. Undrafted rookie Jeff Tuel also is on the roster.
Kevin Kolb left the Bills' game Saturday against Washington because of concussion-like symptoms and first-round pick EJ Manuel is out for the rest of the preseason with a left knee injury.
Leinart, the 2004 Heisman Trophy at Southern California, was drafted by Arizona in the first round in 2006. After four seasons with the Cardinals, he spent 2011 with Houston and last year with Oakland.
Lewis spent the last two seasons with Cleveland. He started the Browns' 2012 regular-season finale against Pittsburgh, completing 22 of 32 passes for 204 yards with a touchdown and an interception.
Kolb was injured in the first quarter when he was kneed in the helmet following an 8-yard scramble. Coach Doug Marrone said it was too soon to determine how much time Kolb could miss. The injury-prone quarterback has had issues with concussions in the past, having sustained two in his first six seasons.
After releasing Tarvaris Jackson earlier in the off-season, the Bills hoped Kolb and Manuel would compete for the starting job at training camp but injuries have gotten in the way.
Kolb missed more than a week of camp after injuring his left knee on Aug. 3. Kolb was hurt when he tripped on a wet rubber mat between practice fields.
Manuel appeared well on his way toward earning the job before he sustained a left knee injury of his own in Buffalo's second preseason game. Manuel has not been ruled out for Buffalo's season opener and the Bills are optimistic regarding his return. He had what the team referred to only as a "minor procedure" after injuring his knee.
AP correspondent Mark Ludwiczak contributed to this report.