Short answer: whether a firm's maximum 'profit' at the point where marginal revenue equals marginal cost is positive or negative depends on whether average revenue exceeds average cost at that point.
To give a simple numerical example, suppose for a firm in a perfectly competitive market:
$$MR = AR = 1$$
$$TC = 2 + 0.4Q + 0.1Q^2$$
where $MR$ is marginal revenue, $AR$ is average revenue, $TC$ is total cost and $Q$ is quantity produced and sold (for a defined period). Then marginal cost $MC$ is:
$$MC = 0.4 + 0.2Q$$
and $MC = MR$ when:
$$0.4+0.2Q=1$$
implying $Q = 3$.
At that point, however, average cost $AC$ is:
$$AC = \frac{TC}{Q} = \frac{2 + 0.4(3)+ 0.1(3^2)}{3} = \frac{4.1}{3} \approx 1.37 > 1 = AR$$
So the firm would make a loss of $4.1 - 3 = 1.1$ by producing at $Q=3$. In this case 'profit' at the point identified by equating $MC$ and $MR$ is only a local maximum within the range $Q > 0$. Note for example that the loss at $Q=2$ is $3.2-2=1.2$ and that at $Q=4$ is $5.2-4=1.2$. The global maximum 'profit' within the range $Q\geq0$ is zero at $Q=0$, so (considering the period in isolation), the firm would do better not to produce at all.