In perfect competition, a firm should produce the number of goods where the marginal revenue (MR) for the last unit produced is equal to its marginal cost (MC).
A firm should shut down in the short run when the MR=MC point corresponds to a price below the average variable cost of making that number of goods/services. If the price is above the average variable cost, the firm should remain in business, even if the price is lower than the average total cost.
In the long run, the firm should shut down if the price at MR=MC is less than the average total cost.
When the MR=MC points corresponds to a price that is equal to average total cost, the firm breaks even (makes zero economic profit). This is the point where equilibrium will occur.
The revenue must equal or exceed the cost of production. Once the revenue is lower, the firm will collapse. When the revenue is more or less similar to the cost of production, equilibrium occurs.