Some brokers have order types specifically designed for this, called "Market On Close" or "Limit On Close". These orders are intended to execute as close to the closing price as possible. Like any market or limit order, market on close will definitely execute but at an unknown price, and the limit on close will definitely get your price but may not execute. The NYSE requires the orders to be submitted by 2:45 CST, and Nasdaq by 2:50 CST and the orders cannot be canceled or modified after that. The exchanges publish imbalances between buys and sells of these closing orders to help attract liquidity.
If your broker does not have these order types, or you want a more flexible solution, you have other options. You can just trade at a time near the close. You probably do not want to trade at the very end (last 5 mins or so) as many market makers begin to withdraw some of their liquidity and price swings can become more volatile. In our experience, if you trade around 2:45-2:55 PM CST on average you will be very close to the closing price of the day.
The best broker for you depends on what you need. Barron's publishes a good annual summary of brokers. Their top rated brokers for Long-Term Investors were Fidelity and TD Ameritrade. For options traders, ThinkOrSwim, tradeMonster, and OptionsHouse got top marks. For Frequent Traders, they recommended TradeStation, MB Trading, Interactive Brokers, and Lightspeed Trading. For international traders, they recommended Interactive Brokers.
Our favorite for day trading, high frequency trading, and automated trading is Interactive Brokers. When you are making many trades per day large commissions can overwhelm even the best strategy. Keep in mind, this is a trade-off as their software and support is more barebones than other brokers, plus all data is sold individually. Regarding automated trading, Tradestation is also well known in addition to Interactive Brokers We like Interactive Brokers better because it has an open API which allows software developers like us to interact with their software using a variety of different technologies and tools. Tradestation is a closed environment so you must use their proprietary language and tools but in exchange you get more 'out-of-the-box' functionality. For a more full-service bundled brokerage, that is good for option trading too, we like ThinkOrSwim (bought by TD Ameritrade). It has powerful software and some innovative features.