With the score tied 3-3 in the sixth, Carl Crawford reached base with one out on second baseman Matt Carpenter's throwing error.
After Nick Punto struck out, Ellis doubled into the left-field corner against Seth Maness (3-1), putting the Dodgers ahead to stay.
Gonzalez socked a solo homer and added a pair of run-scoring hits as the Dodgers evened their three-game series.
Paco Rodriguez (1-2) earned the decision with a scoreless inning of relief and Brandon League picked up his 10th save for Los Angeles, which logged its third win five games.
Yadier Molina went 3-for-4 with an RBI for National League Central-leading St. Louis.