Yep you are right.
On NYSE a pit-guy handles the order and makes the closing print.
On Nasdaq, if not routed to Amex, the moc order is simulated by broker who submits a market order at 3:59:58 or so.
http://individuals.interactivebrokers.com/en/trading/orders/moc.php?ib_entity=llc
Amex...