3 balls are distributed to 3 boxes at random. Number of way in which we set at most 1 box empty is:

Assuming the balls and boxes are distinguishable, you should have multiplied ${3 \brace 2}$ by $3!$ rather than $2!$ in the case where one box is left empty, where ${n \brace k} = S(n, k)$.

Let's look at the case where exactly one box is left empty. Two balls must be placed in one box, and the other ball must be placed in another. There are $\binom{3}{2}$ ways to choose which two balls are placed together in one box. If the boxes are indistinguishable, we place these two balls in one box, and place the other ball in another box. Thus, if the boxes were indistinguishable, the number of ways we can distribute three distinct balls to three indistinguishable boxes so that one box is left empty is $${3 \brace 2} = \binom{3}{2} = 3$$
If the boxes are actually distinguishable, it matters which box receives two balls, which box receives one ball, and which box receives no balls. There are $3!$ such assignments. Thus, the number of ways to distribute three distinct balls to three distinct boxes so that exactly one box is left empty is $${3 \brace 2}3! = 18$$ Since there are $3!$ ways to distribute three distinct balls to three distinct boxes so that no box is left empty, the number of ways to distribute three distinct balls to three distinct boxes so that at most one box is left empty is
$$3! + {3 \brace 2}3! = 24$$

An alternate approach

Assume the boxes are distinguishable from the outset.

No box is left empty: There are $3! = 6$ ways to assign each of the three distinct balls to a different box.

Exactly one box is left empty: If exactly one box is empty, there are three ways to decide which box will receive two balls and two ways to assign a second box to receive the remaining ball. There are $\binom{3}{2}$ ways to decide which two balls are placed in the box which will receive two balls and one way to place the remaining ball in the box which will receive one ball. Hence, there are $$3 \cdot 2 \cdot \binom{3}{2} = 3!\binom{3}{2} = 18$$ ways to distribute three distinct balls to three distinct boxes so that exactly one box is left empty.

Thus, there are indeed $$3! + 3!\binom{3}{2} = 6 + 18 = 24$$ ways to distribute three distinct balls to three distinct boxes so that at most one box is left empty.