Defender Robbie Neilson scored his first goal for Hearts to rekindle the Edinburgh side's hopes of qualifying from Uefa Cup Group A.
Ramon Pereira set up Dennis Wyness then ran over his strike partner's net-bound shot while in an offside position for Hearts' controversial opener.
Argentine substitute Cesar Carignano produced a clever chip over the keeper to give Basel a deserved equaliser.
But Neilson drove the winner home into the far corner in the dying minutes.
Hearts headed into the game knowing they had to leave the Stadion St Jakob-Park with at least a point if they wanted to keep their European dream alive.
But they had to do without the suspended suspended Paul Hartley and Patrick Kisnorbo, Michael Stewart and Joe Hamill coming into the starting line-up.
And Basel started brightly, Scott Chipperfield's cross finding the head of Benjamin Huggel, who nodded just wide.
Boris Smiljanic connected with a Julio Hernan Rossi corner, but he too sent his header past the post.
Craig Gordon prevented Hearts from falling behind in the 18th minute when Matias Emilio Delgado tried his luck with a thunderous long-range effort that the goalkeeper did well to block.
Rossi tried to convert on the rebound with his head, but Gordon was again on hand to deny the home side.
Hearts had a great chance to take the lead when Stewart played the ball through to Wyness, who sent his shot across the face of goal and just wide of the far post.
The visitors did go ahead after 31 minutes, Pereira starting the move that led to Wyness' shot from just outside the six-yard box finding the back of the net.
Both sides were denied shouts for penalties before half-time.
Gordon produced another fine save to stop Chipperfield's diving header on the line as Basel pressed after the break.
Carignano had an effort cleared off the line by Alan Maybury as the home side came close to a late equaliser.
The Argentine eventually levelled the scores after 77 minutes.
But Neilson struck with two minutes of normal time remaining to give Hearts their first points in Group A.
Basel: Zuberbuhler, Zwyssig, Huggel, Sterjovski (David Degen 71), Chipperfield, Gimenez, Kleber, Delgado (Barberis 84), Philipp Degen, Smiljanic, Rossi (Carignano 62).
Subs Not Used: Quennoz, Mandl.
Goal: Carignano 76.
Hearts: Gordon, Neilson, Pressley, Webster, Maybury, Hamill, Stewart (MacFarlane 69), McAllister, Wyness, de Vries (Weir 85), Pereira (Stamp 66).
Subs Not Used: Moilanen, Janczyk, Sloan, Berra.
Goals: Wyness 31, Neilson 89.
Ref: Kristinn Jakobsson (Iceland)