Safina and Dementieva have known each other since childhood
Dinara Safina and Elena Dementieva will fight it out for the gold medal after setting up an all-Russian Olympic final in the women's singles.
Safina battled to a 7-6 (7-3) 7-5 victory over China's Li Na in an error-strewn semi-final.
Dementieva, who won silver in Sydney in 2000, saw off compatriot Vera Zvonareva 6-3 7-6 (7-3) to book her final place.
Venus and Serena Williams reached the doubles final, beating Ukraine's Alona and Kateryna Bondarenko 4-6 6-4 6-1.
Safina, the world number six, had to deal with a partisan crowd on her way to a hard-fought victory over home hope Li, who had already beaten two top-10 players in Svetlana Kuznetsova and Venus Williams on her way to the last four.
In the early stages it looked as though Safina would be too powerful for Li but numerous unforced errors, including a raft of double-faults, undermined the Russian.
Safina squandered three set points as she served for the first set at 5-4 and 6-5 but eventually took it in the tie-break.
More Safina double-faults, including four in one game, handed the world number 42 the advantage in the second set but at 5-3 up her game suddenly disintegrated.
Safina, whose frustration had built with her frequent mistakes, was able to smile again as she broke back to level and broke again with ease to seal her win.
It's a huge moment for Russia - I am sure all the fans back home will be very happy about it
What was her 15th straight singles victory came playing barely 12 hours after she lost a doubles match that finished at 0330 local time.
"It wasn't easy," Safina said. "I didn't sleep enough. I'm just really happy that I could put all my energy into the match and pull out the match."
Safina will play her childhood friend Dementieva after she saw off Zvonareva, who had been a late call-up for the injured Maria Sharapova.
"It's a huge moment for Russia," Dementieva said. "I'm sure all the fans back home will be very happy about it."
The Williams sisters will play Spanish duo Anabel Medina Garrigues and Virginia Ruano Pascual in the final after they beat Chinese pair Zi Yan and Jie Zheng 6-4 7-6 (7-5).