Warren Buffett for years has been giving away some of his considerable wealth to the foundation run by his pals Bill and Melinda Gates.

As a result, the Bill and Melinda Gates Foundation -- along with Gates himself -- now owns more than 5% of Buffett's Berkshire Hathaway.

Berkshire Hathaway (BRKA) disclosed the ownership stake following an annual gift of more than 13.5 million shares on July 16. The shares are worth just under $13 billion. Gates also owns some Berkshire stock apart from the foundation.

Related: Buffett just gave $3.4 billion to charity

According to the SEC filing, the Bill and Melinda Gates Foundation plan to sell 60 million shares by June 30, 2020 to donate to charity.

Buffett is the world's third-wealthiest person. Gates, who co-founded Microsoft (MSFT), is the second. They have been friends for years and Buffett has been gifting money and shares to the Gates foundation -- along with several other philanthropic groups -- since 2006.

In another regulatory filing, Berkshire disclosed that Buffett recently donated more than 1.35 million class B shares to a charity bearing the name of Buffett's late wife Susan Thompson. Buffett also donated 950,000 class B shares to three other charities run by his children.