Not to mention risky - it’s far from guaranteed, especially in the current environment, that your investment over three years will generate better returns than the interest rate on the loan.
If I were in the OP’s position, I think I would consider putting the 401k into investments that might be considered higher-risk than would typically be recommended for a 58 year-old. This is on the assumption that your essential living costs in retirement will be covered by the defined benefit pension. The reason for this is that by investing the 401k mainly in equities (aka shares), as opposed to bonds (which would be the traditional go-to for someone close to retirement), you likely get more protection from rising interest rates/inflation - at the ‘expense’ of greater investment risk. Plus there is the fact that bonds appear to me (and many others) to be very highly-valued right now - as and when interest rates rise, the capital value of bonds could fall quite significantly. Then again, plenty of knowledgeable commentators have been saying this for years, and it hasn’t happened yet. It’s possible the actions of the Fed and other central banks over the last decade and a half have rendered obsolete the sort of thinking in this post, we just don’t know it yet.
Anyway, I digress - on the assumption that this is not the case, my idea is simply that by investing the 401k more in equities, you should be better diversified than having it in bonds. As has already been pointed out, trying to do something more complicated/specific with regard to hedging interest rate risk is likely to be expensive and have its own risks.
One more thing - you mention in the OP simply taking the entire DB pension as a lump sum (I think), presumably on the assumption you can generate a better return by investing it than what the lifetime annuity will provide. This may be true, but it involves you taking on all the investment and longevity risk. Personally I think there’s a lot to be said for having a good baseline of guaranteed ‘forever’ income, even it comes at the cost of investment returns/being able to pass more on to your beneficiaries when you die. And I think most financial advisers would say the same. Of course, that cost is higher the lower interest rates are. But on the other hand, if you agree with it, it means higher interest rates in 4 years’ time are not necessarily all bad news for you.
I hope this makes sense - I’m not sure I’ve explained it very well. As usual, I’m not your adviser, not qualified in your jurisdiction, worth exactly what you paid for it etc.