How to do a ray_cast from camera origin(position) to object in scene in such a way that ray would pas through a given pixel coordinate in camera view?
You obtain the rays like this:

Casting rays from the camera into the scene for each pixel
(2nd part of answer - F12 solution)

Then you build a BVH tree from your mesh:

import bpy
from mathutils.bvhtree import BVHTree

bvhtree = BVHTree.FromObject(bpy.context.active_object, bpy.context.scene)


And you intersect this tree with the ray:

location, normal, index, dist = bvhtree.ray_cast(ray_origin, ray_direction)


You are interested in the location. The index and normal refer to the first polygon it intersected. If there's no hit, it returns (None, None, None, None) tuple.

It's wise to cache the bvhtree for performance reasons, its building is costly, but speeds up ray casting. The tree needs to be rebuild only when the object changes, this you get from the object.is_updated and object.is_updated_data flags.