This paper addresses the problem of optimal grasping of an object with a multi-fingered robotic hand for accomplishing a given task. The task is first demonstrated by a human operator and its force/torque requirements are captured through the usage of a sensorized tool. The grasp quality is computed through a task compatibility criterion. Grasp synthesis is then formulated as a single constrained optimization problem, generating grasps that are feasible for the hand’s kinematics by maximizing the corresponding task-oriented quality criterion and ensuring grasp stability. The method was validated on a human hand model and is shown to be easily adapted to different hand kinematic models.