Statistical Mechanics is the theory of the physical behaviour of macroscopic systems starting from a knowledge of the microscopic forces between the constituent particles.
The theory of the relations between various macroscopic observables such as temperature, volume, pressure, magnetization and polarization of a system is called thermodynamics.
Thermodynamics is an older theory that has studied work, energy, temperature, entropy and related concepts (including volume, pressure, polarization etc.) as continuous quantities describing continuous material objects. It was based on several principles - such as the conservation of energy and the growth of entropy - that prevent one from constructing perpetuum mobile gadgets.
Statistical mechanics is a newer theory that appreciates the atomic structure of the matter. Energy and entropy are distributed among the atoms and the temperature measures the average energy per one atom (or degree of freedom). Statistical mechanics allows one to derive the older laws and principles of thermodynamics by applying statistical methods on dynamics of a large number of atoms and molecules. For a particular model of a material, it even allows one to determine the material constants.
The point of contact between the two disciplines is taken to be the function for Entropy S which is a function of the thermodynamic variables $S=S(U, V, N_i)$ etc, with U being internal energy, V volume. Sometimes this is inverted as: $U=U(S,V,N)$
From a Thermodynamics perspective equations for temperature and other relations can be established by taking derivatives of S or U wrt the variables.
Statistical Mechanics aims to derive S explicitly as a function $S = k \Sigma f_i ln f_i$ where $f_i$ is a possible microstate. The totality of these microstates, and their associated energy, is determined from a partition function.
Both subjects can diverge from here too. Thermodynamic equations met in courses generally refer to equilibrium conditions. Many systems are in non-equilibrium and some thermodynamic theories try to explain this condition and how it changes. Some might argue that the regular thermodynamic concepts like Entropy are not even well defined far from equilibrium.
Statistical Mechanics would differentiate between "classical" systems and various types of "quantum systems" - which have different partition functions and energy behaviour. Thermodynamics is thus often viewed as a limiting classical theory (like Newtonian mechanics), but some Thermodynamic concepts (like Chemical Potential and Temperature) find themselves in quantum partition functions of Statistical Mechanics. In addition Entropy and Temperature are associated with Black Holes for reasons that dont currently translate into Statistical Mechanics.
In Hamiltonian or Lagrangian Mechanics, we can exactly predict the trajectory of the system. The general conclusion is that for Hamiltonian systems we don't have a sufficient number of analytical constants of motion in order to write the solutions down exactly. The systems are generally non-integrable. We use the tools of statistical mechanics to pay attention to systems with a very large number of mutually interacting degrees of freedom. There is no axiomatic derivation of equilibrium statistical mechanics and there are far too many subtleties which are not addressed carefully in the textbooks. In statistical mechanics, we consider microscopic interactions and do the math based on apriori assumptions(postulates).
Thermodynamics deals with averages. It is a science of time-scales and length-scales. Thermodynamics can be defined as the study of systems on their longest length-scales and time-scales so that fluctuations that happen in the shorter time-scales and length-scales are neglected. So what I call thermodynamics on one system may not be the thermodynamics for another system. We have a term called thermodynamic equilibrium which means that for the system the long-time averages of the physically measurable quantities are time independent.
Thermodynamics is the study of thermal and mechanical properties of equilibrium states of macroscopic systems, using the empirical laws of thermodynamics.
Statistical mechanics uses the laws of classical mechanics or the postulates of quantum mechanics, and the principles of statistics to reproduce the thermodynamical properties of macroscopic systems from the microscopical constituents.
Statistical mechanics aims to obtaining expresions for state functions of the systems from microscopic physics.