You can first use the `show_transfers` command in `simplewallet` to see if your transaction shows there. It should show as "pending". Subsequently, you can use the `flush_txpool` command in `bitmonerod` (the daemon). The wallet will shortly notice this and change the status of the transaction from "pending" to "failed". In order to get the right balance, however, you also need to run the `rescan_spent` command in simplewallet. Note that this minor bug (i.e. not showing the correct balance) is fixed in master currently, but not yet present in the binaries (which you are likely using). 

If this doesn't work, you will have to use the `rescan_bc` command in simplewallet.

>Also, what steps can I take to prevent a transaction from getting stuck as pending in the future?

Make sure your daemon is fully synced before sending out a transaction. 

**Sources:** https://bitcointalk.org/index.php?topic=583449.msg16066918#msg16066918