Other answers give good technical answers to what the last message would actually have looked like, but I thought it worth tackling the angle of where the quote came from.
Wikipedia cites an article on LAist a Los Angeles local news / blogging site, written by Jacob Margolis.
In it he describes how he coined the phrase:
"My battery is low and it's getting dark."
That's how I felt when I heard that NASA's Opportunity rover mission was coming to an end after 15 years. That Oppy, the rover, was officially dead, and that it had sent back one last alarming communication to Earth before finding its final resting place in Perseverance Valley on the surface of Mars.
On the evening of Feb 12, 2019, he posted a thread of 11 tweets on Twitter, describing the situation, and including various photos from the rover. Tweet number 3 in that thread reads:
The last message they received was basically, "My battery is low and it's getting dark." They hoped that the windy season would clear dust off the solar panels (if that was the problem). Since then they've been pinging her again and again, every way they knew… 3/
This received numerous responses on Twitter, and as it spread, the context was naturally lost. As Margolis continues:
People started talking about it as if they were actually the exact last words that the rover said. The NY Daily News reported it as fact.
JPL contacted me to let me know that they were being inundated with questions about the final message. And while it seemed like most people understood the context within the tweet, many didn't.
In response to queries about whether these really were "the last words", he says:
As NPR's Scott Simon said, it's a "poetic translation."
He then quotes Deputy Project Scientist Abigail Fraeman:
And then it was Sunday, we actually got a communication from the rover and we were shocked. It basically said we had no power left, and that was the last time we heard from it.
...and John Callas, the project manager:
It also told us the skies were incredibly dark, to the point where no sunlight gets through. It's night time during the day.
In both cases, the "it" seems to refer to the rover, anthropomorphising it; this appears to have been Margolis's inspiration to rephrase the message as a quote in the first person.