Mary Kennedy was legally married to her estranged husband Robert Kennedy Jr. at the time of her death ... TMZ has learned.
RFK Jr. had filed for divorce back in 2010 ... but according to court records, the divorce proceedings were still in progress ... and the judge had NOT yet finalized the split.
In fact, court records show in March the divorce case was headed to trial ... though it's unclear what issues were still in dispute. FYI -- the couple had 4 children together.
But Mary's legal problems didn't end there -- on April 30, just two weeks before she died, Mary was served with a lawsuit filed by American Express ... though the details surrounding the case are unclear.