Yes. Graduation in May qualifies for the credit calculation.
Per the IRS, "To qualify as a student, the person must be, during some part of each of any five calendar months of the year". If you graduated on May 1st, then the entire month of May counts as one of your five months and since you started in January and graduated in May, this will count as 5 months.