I teach both engines to my college students, and speaking both as an educator and as a source code contributor to UE4, they're both pretty sweet, but very different in their structure and approach.
Historically they have targeted different market segments - Unity for the hobby/indie market and UE for the AA+, big budget projects.
UE4 changed that by being available to everybody on modest budget, basically they are gunning for Unity's defacto monopoly on small hobby projects.
Unity uses C# for its code (so little/no memory management for my fledgling game designers to have to bother with), and unreal uses C++ and a visual scripting language called Blueprint.
Unity is closed source, UE4 is source-available (you can develop games using existing binary builds or build the engine from source, making whatever changes you want).
Unity has historically relied on its asset store for additional features like visual scripting, shader editing, etc.. This means you can literally just pay for whatever functionality you need from third-party developers and mash it together to get what you want. UE4 uses a much more kitchen-sink type approach, including a lot of features as standard, though of course this means that the engine is large (not bloated in the sense of full of unnecessary crap, but the codebase is currently 11,000+ files).
Unity is faster to start developing in if you want to code everything, rather than use a mixture of C++/Blueprint. On the other hand UE has many visual-editing tools designed to let you develop as much as possible without having to start coding at all.
UE4's source code is a very valuable educational tool, too. Want to know how a professional PBR rendering system is written? Simply open up the files and start reading. Proper reflection system in C++? Same. Most of the source is self-documenting with good comments.