Superstar LeBron James had led Cleveland on a 22-4 scoring run earlier in the fourth quarter, and the Cavs led by six with 32.5 seconds remaining.
But Cleveland couldn't seal the victory from the foul line.
Zydrunas Ilgauskas missed one of two free throws with 5.6 seconds to play, leaving Utah needing one basket to tie - or a three-pointer to win the game.
After a timeout, Utah's Ronnie Price got locked up behind the three-point line and managed to get the ball to Gaines, who drained the winner.
Gaines, who signed to a 10-day contract with the Jazz when starter Deron Williams sprained his right wrist earlier this month, finished with nine points in nine minutes. He notched his first three-pointer in five career NBA games.
Williams was back in action on Thursday before re-injuring his right wrist early in the fourth quarter in a collision with Mo Williams - an injury that led to Gaines going into the game.
Utah also lost forward Andrei Kirilenko in the third quarter with a hyper-extended right knee.
James led Cleveland with 36 points, scoring 20 in the fourth quarter, but the Cavaliers committed a season-high 23 turnovers.
Source: AFP American Edition