How is allocative efficiency achieved in pure competition?
The assumptions of perfect competition (among both sellers and buyers) lead to an equilibrium price and quantity that cannot be improved in terms of allocating resources.
I have created a FlockDraw chart to help explain this, here.
In perfect competition, all buyers have equal access to the same technologies, no barriers to entry, and no market power. Likewise, all consumers have equal access to information and no market power. Externalities and other market failures do not exist. Under these conditions, the market equilibrium is efficient, or optimal. No other market outcome will improve society's overall well-being, as measured by the sum of producer and consumer surplus.
In the chart, the height of the demand curve is a proxy for the marginal social benefit -- the value that the marginal buyer attaches to the consumption of the next unit. Likewise, the supply curve is a proxy for the marginal social cost -- the value of the resources used to produce the next unit.
At equilibrium, the marginal social benefit equals the marginal social cost. Producing and consuming one unit less than the market equilibrium would reduce overall benefit by the marginal social benefit minus the marginal social cost. Since, to the left of equilibrium, marginal social benefit is higher than marginal social cost, this would reduce overall benefit. In other words, we could conserve resources by reducing production and consumption, but we would give up more in benefits than we would save in costs.
Likewise, producing and consuming one unit more than the market equilibrium would also reduce overall benefit. To the right of the equilibrium, marginal social benefit is lower than marginal social cost. In other words, we could produce and consume more than we do at equilibrium, but the marginal benefits of doing so would not be worth the additional cost.
This is the "classical economics" explanation of efficiency. Please note that it depends on some heroic assumptions that are almost never matched in reality. Note also that economics has a utilitarian bias, if you are using this to make a normative argument.