A Hamilton-Jacobi-Bellman (HJB) equation based optimal control algorithm is proposed for the robust control of a bilinear system. The HJB equation is formulated using a suitable cost functional to tackle system uncertainties and constraints on the input. Utilizing the Lyapunov direct method, the controller is shown to be optimal with respect to a cost, which include penalty on the control effort and system states, and upper bound on the system uncertainties. The controller requires the knowledge of the maximum bound of system uncertainties. In the proposed algorithm, Neural Network (NN) is used to find approximate solution of HJB equation using least squares method. Proposed algorithm has been applied on bilinear systems with matched and unmatched uncertainties. Necessary theoretical and simulation results are presented to validate the proposed algorithm.