Twelfth seed Shemyakina, who was 18th at the Beijing Games four years ago, worked her way through the preliminaries here with two key victories over top-ranked Romanian fencers.
She beat fifth seed Ana Maria Branza and then knocked out another Romanian in fourth-ranked Simona Gherman.
Heidemann reached the gold-medal match after a controversial incident in her semi-final against Shin A Lam sparked a one-hour protest.
The South Korean refused to leave the piste, as was her right under the rules, until all protests by her federation failed.
"The German must still have been thinking about the semi-final and wasn't able to focus as much on my bout," Shemyakina said through a translator.
The controversy erupted over whether the clock was counting down correctly.
"I am not blaming the argument for my defeat but on the other hand it did cause me stress," said Heidemann.
"Of course I would have loved to take my second gold medal but after five tough matches here I think I have won silver and not lost gold."
Shin came back to fence in the bronze-medal match but lost 15-11 to number one seed Sun Yujie of China.
Earlier, the Korean protested against a controversial call for one hour in the semi-final with Heidemann.
Shin was physically escorted off the piste after her team argued against a call that awarded a winning touch to the German.
Shin sat slumped with a towel round her, emotions frayed by watching four years of dreaming of gold end in abject misery.
"I don't understand how this could have happened. The one hour was really difficult for me and my feelings," Shin said through an interpreter.
Heidemann, a one-time Playboy model, said she did not blame Shin for the incident.
"It is neither her nor my fault. After the decision the Korean coach came to me and also to my coach and we hugged each other and said we are sorry for each other. I think that was really a fair gesture and I appreciate that," said the German.
Shemyakina took advantage of the extra time between the semi-finals and the final, discussing tactics with her coach.
According to the Ukrainian champion, the crowd may have played a part in disturbing Heidemann's concentration for the final after the fans had applauded Shin as she sat with the spotlight on her pristine white uniform in a darkened sports hall.
"In the dressing room you could hear how the crowd supported the Korean fencer and that upset the German a little bit," said Shemyakina.
"It may have affected her but there was no way I was giving the medal away. She already has a gold and there's no way I was going to give this one to her."