(CNN) Lucas di Grassi won a thrilling Mexico E Prix, pipping race leader Pascal Wehrlein as his battery died on the line.

Mahindra's Wehrlein led for large parts of the race but his battery's charge hit 0% just meters from the end, allowing Di Grassi to pass him on the inside.

The German driver was eventually demoted to sixth place after a five-second penalty for cutting off a chicane, as Antonio Felix da Costa and Edoardo Mortara came second and third respectively.

"I pretended to go to the outside and he opened a small door, just enough for the car to fit between the wall and the car and I went there," a shirtless and champagne-soaked Di Grassi told reporters of his last-gasp overtake.

Read More