The Mavericks staged a 6-0 run down the stretch to pull within 98-94 with 2:02 left to play, but Foye (17 points) answered with his fifth 3-pointer of the game a minute later to seal the win.
Kenneth Faried chipped in with a double-double of 18 points and 14 rebounds.
Dirk Nowitzki supplied 27 points and nine rebounds, but his score-tying try at the buzzer came up short for Dallas, which had its four-game winning streak snapped.
Monta Ellis scored 25 points.
2014: NFL Cheerleaders [PHOTOS]
Michael Sam cut from the Dallas Cowboys