Mustafina's near-perfect routine gave her a score of 16.133, with China's 2008 champion He Kexin taking silver with 15.933.
Tweddle, who agonisingly missed out on a medal in Beijing, executed a high difficulty routine but lost 0.3 for a shaky dismount, giving her a total of 15.916.
American all-round champion Gabrielle Douglas, competing last, took a free swing after hesitating on the higher bar and suffered with a score of 14.900 and last place.
It is Britain's first women's Olympics gymnastics medal in the history of a sport dominated by China, USA and Eastern European nations.
Tweddle's medal was also Britain's fourth at these Games, adding to a men's team bronze, and silver and bronze for Louis Smith and Max Whitlock in the pommel horse.
It is expected to be the 27-year-old's Olympic swansong, and crowns several gold medals won at World, European and Commonwealth events.
Tweddle - a veteran in the teenager-dominated women's gymnastics - can now retire happy, saying she just wanted a medal to finish her career.
"This is the one medal that I wanted to finish my career. It was the one that was missing from my collection; I wasn't bothered what colour it was.
"It is my third Olympics, everyone knows I wanted this one medal to be able to finish my career happy. This was the one thing that was missing."
Britain's greatest female gymnast explained that a knee operation before the Games left her wondering if she would ever realise her dream.
"Twelve weeks ago I couldn't think about competing here. I cried myself to sleep back then because I thought it was the end of my Olympics," she said.
"Tonight it will be easy to sleep, because I have a medal."
The gold medal completed a set for the 17-year-old Mustafina, after she won team silver and all-around bronze last week.
Her team mate, the world and European bars champion Victoria Komova, who spent much of the first week in tears after missing out on all-around and team gold, had been expected to be Russia's biggest medal hope on the apparatus.
Judging by Komova's miserable expression as she stepped down after finishing her routine, however, the teenager already knew she had missed out again and she ended up fifth with 15.666.
Mustafina, by contrast, was a picture of smiling delight as she finished her routine and high-fived her coach. She has now outdone her father, Greco-Roman wrestler Farhat Mustafin, who won a bronze at the 1976 Montreal Games.
China's He, who was at the centre of allegations in Beijing that the home team were fielding under-age gymnasts - charges they denied, set the standard when she opened the final with a dazzling routine and a mark of 15.933.
Mustafina was sixth up and then waited to see if Douglas, starting last, could follow up on her all-around and team golds.
Douglas, 16, is known as the "Flying Squirrel" for the shape she makes on her favourite apparatus but could not reproduce her form of last week.
American fans at the North Greenwich Arena suffered with her as she averted her gaze from the scoreboard while waiting for her mark to flash up.
- Related links