We are considering Total Cost $(C)$as a function of output, $q$, $C= C(q)$.
Average Cost is defined as
$$AC \equiv \frac {C(q)}{q}, q>0$$
Finding the minimum average cost production level $q^*$requires to set $AC$'s derivative equal to zero
$$\frac {dAC}{dq} = 0 \Rightarrow \frac{C'(q)q-C(q)}{q^2} = 0 \Rightarrow C'(q)q-C(q) = 0$$
$$\Rightarrow q^*: C'(q^*)=\frac{C(q^*)}{q^*}$$
(and you want the cost function to be convex, $C''>0 in order for this to be a minimum).
But $C'(q^*)$ is the marginal cost function calculated at $q^*$, so
$$ q^*: MC(q^*)=AC(q^*)$$
In other words, at $q^*$, average and marginal cost coincide.
Now, we have to remember that in Economic Theory the concept of "profit" has nothing really to do with how the word is understood in every day business, or say, in Accounting. "Profit" is above and beyond some measure of "normal returns to capital", while Accounting profits, the "bottom line", have not subtracted from revenues capital returns fully (they have subtracted the returns to foreign-borrowed- capital, but not the returns to own capital). So roughly speaking, Economic Theory sees Accounting profits as "own capital returns" -and will characterize a portion of them as "profits" only if said portion exceeds the "normal rate of own capital return", however this is measured.
Why this digression? Because in competitive markets the argument is that firms are more or less "price-takers" (they may "set the prices" but they have to eventually adjust them due to competition), meaning that the revenue function is linear in the price, and so marginal revenue does not depend on the quantity produced by a single company. Moreover, competition will drive the price down enough so that economic profits (as defined above) are extinguished: but this means that total revenue will equal total cost, and so marginal revenue (which equals average revenue here), will equal average cost. Since the company equates marginal revenue with marginal cost, this leads us to the conclusion/prediction that what we observe is companies producing at a point where all three are equal -and marginal cost is equal to average cost when the firms produce at $q^*$ level.
On the practical side of things, producing at minimum average cost, maximizes your chances to make, after all, a profit, in the economics sense of the word. Note that the above imply that when doing cost calculations, in "costs" we should include the "opportunity cost of own capital", which is another way to talk about the "normal" returns to capital.
And yes, when market imperfections, market power, market asymmetries, market externalities, are taken into account, the above picture becomes an approximate benchmark case -and it is then when things get really interesting.