Bette Midler gifted Kim Kardashian with a tree years ago before turning Kim's Instagram nude into a punchline ... TMZ has learned.
By now you know Kim took extreme exception to Bette's cyber-jab -- saying, "hey @BetteMidler I really didn't want to bring up how you sent me a gift awhile back trying to be a fake friend then come at me."
Now, we know ... that "gift" was a tree that Bette planted in Kim's honor as part of Bette's New York Restoration Project.
Bette dedicated one of the trees to Kim when she launched her MillionTreesNYC initiative in 2007 -- and even sent Kim a handwritten note.
We're told Kim believed the gesture was a friendship branch ... until Bette mocked her on Twitter.
As for Bette, she just fired back at Kim saying, "I never tried to fake friend you. Looks like anyone can take a selfie but not everyone can take a joke."