I read this story in one of the many anthologies I've had over the years but can't find it. The protagonist is a scientist. Something goes wrong with an experiment and he starts skipping forward through time. It's only when he gets to the death of the last human that time resets and he returns to his present.
"Flight to Forever", a novella by Poul Anderson, which was also my (unaccepted) answer to this old question. First published in Super Science Stories, November 1950 (available at the Internet Archive), it has been reprinted a number of times; does any of these covers ring a bell?
The story matches your description fairly well, except that the protagonist has to go way past the death of the last human, even past the death of the whole universe, to get back to his own time. The adventure starts when the protagonist decides to ride his time machine 100 years into the future to find out why the automatic machines didn't come back. (Bad idea.) He learns that an unknown law of nature makes it impossible to travel more than a short distance backwards in time:
It took two hours to fight back five years. Then Saunders stopped the projector. His voice shook.
"No go, Sam. We've used up three quarters of our stored energy—and the farther back we go, the more we use per year. It seems to be some sort of high-order exponential function."
"So we'd never make it. At this rate, our batteries will be dead before we get back another ten years." Saunders looked ill. "It's some effect the theory didn't allow for, some accelerating increase in power requirements the farther back into the past we go. For twenty-year hops or less, the energy increases roughly as the square of the number of years traversed. But it must actually be something like an exponential curve, which starts building up fast and furious beyond a certain point. We haven't enough power left in the batteries!"
Unable to go back, they start "skipping forward through time", hoping to find some advanced civilization that can send them back.
2500 A.D. The machine blinked into materialization on top of a low hill—the pit had filled in during the intervening centuries. Pale, hurried sunlight flashed through wind-driven rain clouds into the hot interior.
[. . . .]
3100 A.D. A waste of blackened, fused rock. Saunders switched on the Geiger counter and it clattered crazily. Radioactive! Some hellish atomic bomb had wiped Liung-Wei from existence. He leaped another century, shaking.
3200 A.D. The radioactivity was gone, but the desolation remained, a vast vitrified crater under a hot, still sky, dead and lifeless. There was little prospect of walking across it in search of man, not did Saunders want to get far from the machine. If he should be cut off from it. . . .
By 3500, soil had drifted back over the ruined land and a forest was growing. They stood in a drizzling rain and looked around them.
[. . . .]
4100 A.D. They flashed into materialization on a broad grassy sward where low, rounded buildings of something that looked like tinted plastic stood between fountains, statues, and bowers. A small aircraft whispered noiselessly overhead, no sign of motive power on its exterior.
[. . . .]
4300 A.D. The campus buildings were gone, but small, elaborate summerhouses had replaced them. Youths and girls in scanty rainbowhued dress crowded around the machine.
[. . . .]
4400 A.D. A villa was burning, smoke and flame reaching up into the clouded sky. Behind it stood the looming hulk of a ray-scarred spaceship, and around it boiled a vortex of men, huge bearded men in helmets and cuirasses, laughing as they bore out golden loot and struggling captives. The barbarians had come!
After a few more stops they arrive in 50,000 A.D., where a big part of the story takes place in the court of the Empress Taury.
The four squeezed into the aircraft and it lifted with a groan of ancient engines. Vargor gestured at the fortress ahead and his tone was a little wild. "Welcome to the hold of Brontothor! Welcome to the Galactic Empire!"
"Aye, this is the Empire, or what's left of it. A haunted fortress on a frozen ghost world, last fragment of the old Imperium and still trying to pretend that the Galaxy is not dying—that it didn't die millennia ago, that there is something left besides wild beasts howling among the ruins." Vargor's throat caught in a dry sob. "Welcome!"
Eventually, around 4,000,000 A.D.:
He was in a city. But it was not such a city as he had ever seen or imagined, he couldn't follow the wild geometry of the titanic structures that loomed about him and they were never the same. The place throbbed and pulsed with incredible forces, it wavered and blurred in a strangely unreal light. Great devastating energies flashed and roared around him—lightning come to Earth. The air hissed and stung with their booming passage.
The thought was a shout filling his skull, blazing along his nerves, too mighty a thought for his stunned brain to do more than grope after meaning:
CREATURE FROM OUT OF TIME, LEAVE THIS PLACE AT ONCE OR THE FORCES WE USE WILL DESTROY YOU!
Through and through him that mental vision seared, down to the very molecules of his brain, his life lay open to Them in a white flame of incandescence.
Can you help me? he cried to the gods. Can you send me back through time?
MAN, THERE IS NO WAY TO TRAVEL FAR BACKWARD IN TIME, IT IS INHERENTLY IMPOSSIBLE. YOU MUST GO ON TO THE VERY END OF THE UNIVERSE, AND BEYOND THE END, BECAUSE THAT WAY LIES—
He screamed with the pain of unendurably great thought and concept filling his human brain.
GO ON, MAN, GO ON! BUT YOU CANNOT SURVIVE IN THAT MACHINE AS IT IS. I WILL CHANGE IT FOR YOU . . . GO!
The time projector started again by itself. Saunders fell forward into a darkness that roared and flashed.
Saunders goes on and on:
A hundred billion years in the future, the sun had used up its last reserves of nuclear reactions. Saunders looked out on a bare mountain scene, grim as the Moon—but the Moon had long ago fallen back toward its parent world and exploded into a meteoric rain. Earth faced its primary now; its day was as long as its year. Saunders saw part of the sun's huge blood-red disc shining wanly.
So good-by, Sol, he thought. Good-by, and thank you for many million years of warmth and light. Sleep well, old friend.
Some billions of years beyond, there was nothing but the elemental dark. Entropy had reached a maximum, the energy sources were used up, the universe was dead.
The universe was dead!
He screamed with the graveyard terror of it and flung the machine onward. Had it not been for the gods' command, he might have lit it hang there, might have opened the door to airlessness and absolute zero to die. But he had to go on. He had reached the end of all things, but he had to go on. Beyond the end of time—
Finally the universe reforms and he gets back home:
He walked into the living room and smiled at Eve and MacPherson. "Hello," he said. "I guess I must be a little early."