529 disbursements and Education Credit deduction Question

I am confused.  My son is a full time student, claimed as a dependent on a married filing jointly tax form. I have a 529 Education Fund and received a disbursement to me from that account which I used all of to pay for his entire Tuition, Fees and Room and board.  On Turbo Tax, when I enter all  the information, I get a notice that if I claim that some of the disbursement was taxable, I can then claim up to $4000 as an Education credit.  When I recalculate claiming this $4000 I can save another $1000 in taxes!  Is this legal?  To claim I took a $4000 disbursement from the 529 that wasn't for qualified education expenses (disbursement was sent to my bank account) and pay taxes on that, then turn around and say I had to pay another $4000 for his tuition from my pocket and claim the $4000 education credit?  My son meets all the qualifications for the credit.  Of course I want to save on taxes but it feels like I am not understanding something.  Please advise.  Can I legally do this?  Or maybe claim $3583 so it looks better?