Williams, who teamed up with Ram at short notice for the tournament, looked on course for a fifth gold when taking the first set.
But she had to settle for silver after fellow Americans Bethanie Mattek-Sands and Jack Sock downed the 36-year-old and Ram 6-7 (3/7), 6-1, 10-7 to grab the gold.
'You always go into a match trying to win it and you never know if you are going to be able to cross that line,' said Williams, who had to be content with a record-equaling fifth medal in total.
'So I really feel just excited that we played really well the whole tournament.'
She added: 'I'm excited that we had chances and put ourselves in a position to win that match and you can't ask for more.