Having a large amount of credit card debt is pretty much always a financial calamity that needs quick remedy. The 20% interest you pay vastly outstrips what you can get with any kind of certainty in any investment. There are plenty of historical periods where investments have beaten 20%, even in a small amount of time, but often investments are flat or negative. Investment returns can't be counted on. As a rule, there is no question that paying off the credit cards is more important than investing.
Though, your question has one subtlety: The invested money is currently in your 401(k). Your age is not clear from the question. If you are not of age to be able to pull this out without paying a penalty, it's less clear that you should. Giving the government an immediate 10% penalty from your 401(k) plus the associated income taxes is a bad thing. If you are talking about borrowing from your 401(k), then that might be more reasonable, as long as you intend (and are able) to repay that loan in a reasonable amount of time.
I would say if you are borrowing from your 401(k) it's probably a good idea, if you are at an age in which you can withdraw penalty free it's a no-brainer, if you are thinking of taking the government penalty on that money, then you may want to explore other approaches.
It goes without saying that whatever you do to handle the immediate problem, you must also change the factors that caused the problem. If you wish to have financial security and good habits, get into the practice of paying off your credit cards completely every month.