My first marathon I finished in about 4:30. There were a number of things that impacted my training, so I knew my time wouldn't be great, but figured I could finish. And like you describe, my legs were pretty done before I was finished.
Decided I needed to do it again with better training and a better plan. Walked the big hill, watched my pace better through the beginning, had a better plan for water, gels, etc. I ended up taking about an hour off my time, last 6 miles were my fastest splits of the race, and felt great when I was done.