AT&T nowadays gives a means to unlock AT&T branded iPhones for free of charge. There are several ways to do so such as calling customer care, emailing AT&T customer service etc. However I found the way below is most suitable to do so.
Find out the IMEI of the iphone in General -> Settings -> About
Go to the AT&T link and fill out the unlock request form. You do not essentially need to be AT&T client. Unless you are existing or old client of AT&T, you will need to email them a copy of the purchase receipt.
AT&T will provide you instructions to unlock the form in several days.
Check the lock status of the iPhone or here to verify that the phone is unlocked.
Occasionally AT&T will send you an email indicating the phone cannot be unlocked, it is because that the iphone may have been reported missing or stolen.
However, AT&T no longer requires the contract commitments on the mobile phone to be fulfilled.