A curious tourist accidentally took a trip back to 1865 when she wandered into a century-old fortress and former prison on Governors Island — and got locked inside.

Shakira Stover, 35, who is American but lives in Spain, said she got a taste of 19th-century jail life Wednesday as she wandered around Castle Williams, a stone fortress built on Governors Island in 1811 to protect New York Harbor from the British.

It housed Confederate prisoners during the Civil War and served as a military prison until 1965.

“I was looking around, reading about the history, and when I finished, I go to walk out the same way I came and the big double doors were closed,” Stover told The Post.

She tried to push them open. but a thick, black barrel bolt sealed with a padlock prevented that.

“I go through the inside to see if there’s another way out and, it’s a prison. There is no other way out!

“At that point, I’m freaking out a little bit because no one’s there with me.”

She found a dusty old landline by the front door of the fortress and frantically punched in some numbers, but the relic didn’t work. Her cellphone didn’t either.

“At that point, I really started to panic,” she said.

Stover rushed back to the front and, like many prisoners likely did before her, wedged her arms through a small opening in the doors and started screaming to be let out.

“I see people, and I get excited and I started yelling, but no one could hear me because the wind was blowing in my direction,” recounted Stover, who’s in the city for a summer nursing job.

Her voice growing hoarse, Stover’s hope was dwindling and she grew desperate.

Finally, two British tourists heard her screams and came to her aid.

They sent for a security guard, who rolled up in a golf cart and demanded to know what Stover was doing inside the locked building, which apparently closes at 4:30 p.m., an hour and a half before the island closes on weekdays and about the same exact time Stover entered the castle.

“What do you mean, ‘What am I doing here?’?” Stover retorted. “I was walking around like a normal person and you guys left me in the prison!”

The guard didn’t have the key, nor did the manager. Finally, a grumpy park ranger showed up and knew the code to the padlock. (Apparently, 1776 didn’t work.)

Despite feeling “like forever,” Stover’s prison term was over within an hour and she was set free.

As a lover of national parks, she said she’d “probably go back,” but is in no rush.

“I just really wanted to get on the ferry and get off the island,” she said.