  An in-depth theoretical study is carried out to examine the
quasi-deterministic entanglement of two atoms inside a leaky cavity. Two
$\Lambda$-type three-level atoms, initially in their ground states, may become
maximally entangled through the interaction with a single photon. By working
out an exact analytic solution, we show that the probability of success depends
crucially on the spectral function of the injected photon. With a cavity
photon, one can generate a maximally entangled state with a certain probability
that is always less than 50%. However, for an injected photon with a narrower
spectral width, this probability can be significantly increased. In particular,
we discover situations in which entanglement can be achieved in a single trial
with an almost unit probability.
