The 33-year-old, who played 12 limited-overs games for England in 2007-08, joined Gloucestershire on loan in July.
Mustard holds the Durham record for appearances in first-class and T20 cricket, helping them win five trophies during his time at the Riverside.
"What I saw in the team during the five weeks on loan was very pleasing," he told Gloucestershire's website.
"Gloucestershire gave me the opportunity to play red ball cricket this summer and it was fair to give them the first shot at putting a contract on the table."
Mustard spent 16 years at Durham - who were relegated to Division Two over financial issues on Monday - and has scored 8,098 first-class runs so far in his career.
He also had a loan spell with Lancashire during the 2015 season.
Meanwhile, Gloucestershire seamer Tom Hampton - who has played four first-class matches so far in his career - has left the club after his contract expired.
Gloucestershire have signed Durham wicketkeeper-batsman Phil Mustard on a two-year deal following a loan spell.