Roth IRA Early distribution

Last year I opened a Roth IRA account and contributed 10k (after tax). Several months later I realized my income exceeded the Roth IRA cap, so I withdrew all the 10k and 400 capital gain. When I'm reporting tax this year, TurboTax calculated 3.5k federal tax due for my Roth IRA "early distribution". What can I do to avoid this?