Template metaprogramming is a technique in C++ that uses templates to perform computations at compile time, enabling more efficient code execution and type safety. It leverages the compiler's ability to generate code through templates, allowing developers to write generic and reusable code that is optimized during compilation.