The pain felt by many longtime Medtronic Inc. shareholders is turning into a big gain for their favorite charities.

Longtime holders of stock in Fridley's medical technology giant were stunned to learn earlier this year that they'll face potentially large tax bills when Medtronic moves its legal headquarters to Ireland, which is expected to happen early next year. Older shareholders complained directly to Chief Executive Omar Ishrak in August that they didn't have cash to pay the unexpected tax.

For some of them, frustration has since given way to pragmatism. Tax planners and local charities say many longtime holders of stock have decided to offset or even wipe out their Medtronic tax liabilities by donating some or all of their shares to charity. Depending on when and how such donations are made, stock donations can create income tax deductions and reduce or eliminate capital-gains taxes, though individual situations vary widely.

And the charities have figured it out. Some are directly soliciting donations of Medtronic stock, which the company encouraged last week by announcing it would match up to $1 million in stock donations to Greater Twin Cities United Way. Meanwhile the Minneapolis Foundation is promoting the creation of donor-advised funds with Medtronic shares, which would allow donors to see immediate tax deductions while spreading out the giving over future years.

"To people who have the means to do a large charitable contribution, this is by far the best answer they're going to get on this," said David Brauer, head of the tax department at Minneapolis tax accounting firm Lurie Besikof Lapidus & Co. "For those not in a position to do a large charitable donation, they're left with selling some of the stock to fund the tax, most likely."

For those who do donate stock, timing can be critical.

In order to wipe out the 30 percent tax on the gain in value of Medtronic stock, a donor would have to give it to charity before the company closes its proposed deal. Medtronic is planning to execute the biggest merger in its history, acquiring Dublin-based health care supplier Covidien for $42.9 million stock and debt, and then moving the combined company under a corporate parent based in Ireland, where business taxes are about a third of the U.S. rate of 35 percent.

The deal would be taxable for shareholders because they would in effect be exchanging their shares in the current Medtronic for an equal amount of stock in the new company, called Medtronic PLC.

Last Thursday, Ishrak sent a note to employees and retirees announcing that the deal will not take place until early next year, providing some sought-after flexibility for potential stock donors. If the deal had gone through this year, as was possible, the full capital-gains taxes for shareholders would have come due next April.

Completing the inversion next year most likely means the taxes will be due in April 2016, though not all advisers agree on that point.

"Because this transaction is a taxable event for many shareholders, we wanted to share this with you as soon as possible for tax and other planning purposes," said Ishrak's note. "Many of you have asked if you could spread the sale of Medtronic shares over a two-year period. We recommend you contact your financial adviser(s) to better understand how a closing in 2015 might impact you."

Shareholders who already donated stock in anticipation of a closing this year aren't out of luck, however. Tax experts say the value of a stock donation can be carried forward as a deduction against income taxes for up to five years.

"For someone who acted too early in this calendar year, they won't get penalized for it," said William Sternberg, vice president of philanthropic services at the Minneapolis Foundation, a nonprofit that makes grants to other charities and manages charitable funds on behalf of more than 1,000 families and businesses.

Sternberg said he's already set up donor-advised funds using Medtronic stock in response to the Covidien deal. For tax purposes, the value of donations into such funds can be taken immediately on taxes, even though the fund can distribute the money to individual charities over a long period of time. Sometimes heirs take on the duty of distributing the money in donor-advised funds.

"It's a great tool to store charitable dollars for future use, potentially for future generations," he said.

On the other end of the spectrum is United Way, which vows to distribute all donated money to charities within one year.

Barb Beard, senior vice president of major gifts at Greater Twin Cities United Way, said stock donations are a common vehicle to support charities of all types that are large enough to be able to convert equities to cash. The unique aspect of Medtronic's deal is that it is forcing the timing of donations, which United Way would convert into quick donations to smaller charities that provide food, shelter and family support.

"People who are interested in making an impact today, they would like to see their dollars at work in the community, helping kids succeed and stabilizing families and nurturing healthy behaviors," Beard said. "If you want to see the impact of those dollars, we are one of the best places to give."

While some donors may give away their entire Medtronic portfolio, many will not. The timing of donations in those cases is critical as well, because recognizing a capital gain on some Medtronic shares will allow a donor to deduct losses on other stocks, so long as the losses don't exceed the capital gain.

But experts don't recommend making decisions about charitable giving based solely on the personal strategic tax reasons.

"We would never recommend that anyone's first consideration be tax implications," said Christopher Watkins, a managing director at UBS Financial Services. "Regardless of how many shares you own, or what the tax implications are, you are literally giving it away. The first decision has to be whether you want to give it away."

Joe Carlson • 612-673-4779

Twitter: @_JoeCarlson