A key piece of information we don't have, but Space-X does, is how much fuel was left at landing. Landing has to be done with minimum fuel, since it comes out of the fuel budget for putting payload into orbit. They have thrust vectoring on the main engines, and have attitude jets near the nose. They have to land vertical, at near zero velocity, with near zero angular rate, with an underactuated system. Underactuated means there are more degrees of freedom to control than there are controllable parameters. They have 5 controllable degrees of freedom - 2 axes of engine vectoring, main engine throttle, and 2 axes of relatively weak nose thrusters. They have to hit a point with three translation constraints, three linear velocity constraints, two angular constraints, and two angular rate constraints. So they have 5 DOF in and 10 DOF out. That, mathematically, is what "rocket science" is.
This under-actuated maneuver has to be solved as a two-point boundary problem, or, in practice, re-solved continuously to cope with problems such as wind gusts. You can see what happened; they had too much angular rate at landing, requiring more torque than the nose thrusters could impart to keep the rocket upright once the main engines could no longer help. It looks like they made a big correction shortly before landing to hit the target, and lost angular stability doing so.
If they'd had a bigger landing area, so they didn't have to apply big corrections to hit the tiny target, this would have worked.