Well, if I am working agile, I NEVER overshoot a sprint. I don't even think about it. I rather take a blame for questionable architecture or dubious implementations. Or for missing features in a sprint review.
I would leave refactoring to the next sprint then and make sure your product owner knows why you are doing it and why feedback from the sprint retrospective requires you to refactor an implementation.
This is me reading you guys' comments: