Tantra as a post-Vedic Hindu Yogic movement began in North India and flourished in the middle ages before declining in the nineteenth century, partly as a result of persecution by the British and orthodox Hindus, and partly, perhaps, because of the increasing popularity of Bhakti yoga amongst the masses.
Legend ascribes the origin of Tantra to Dattatreya, a semi-mythological yogi and the author of the Jivanmukta Gita ("Song of the liberated soul"). Lord Adinath, or Shiva, is the first Guru of Tantra. Things become a little more clear with Matsyendranath (Master of fish). He is accredited with authorship of the Kaulajnana-nirnaya, a voluminous ninth-century tantra dealing with a host of mystical and magical subjects, and occupies an important position in the Hindu tantric lineage, as well as in Tibetan Vajrayana Buddhism. His disciple, Gorakhnath, founded laya yoga. Hatha Yoga was penned by Swami Swatamarama as the secrets of Lord Adinath (another name for Shiva) in the 15th century.
Tantra evolved into a number of orders (sampradaya) and diverged into so-called "left-hand tantra" (varma marg), in which sexual yoga and other antinomian practices occurred, and "right-hand tantra", in which such practices were merely visualized. Both groups, but in particular the left-hand taantrik, opposed many features of orthodox Hindu culture, particularly the caste system and patriarchy. Despite this, Tantra was accepted by some high-caste Hindus, most notably the Rajput princes. Hindu tantra even briefly enabled a yogic/sufi synthesis among some Indian Muslims. Nowadays Tantra has a large, though not always well-informed, following worldwide.
Buddhist and Hindu Tantra, though having many similarities from the outside, do have some clear distinctions. Scholars are unable to determine whether the Hindu or the Buddhist version of Tantra appeared first in history. Buddhist Tantra is always part of the Mahayana school of Buddhism, which has as main aim to help all sentient beings becoming free from problems (Dukkha), in order to achieve this aim, one should try to achieve Buddhahood oneself, in order to be the most profound teacher for others. Buddhist Tantra spread out from (North) India, chiefly to Tibet, where it became known as the Vajrayana school of Buddhism. It also had some influence on Chinese and Japanese Buddhism (notably Shingon).