SAN FRANCISCO — Apple has become the world’s first publicly traded company to be valued at $1 trillion.

The milestone marks the triumph of stylish technology that has redefined what we expect from our gadgets ever since two mavericks named Steve started the company 42 years ago.

The peak reached Thursday seemed unimaginable in 1997 when Apple teetered on the edge of bankruptcy, with its stock trading for less than $1.

To survive, Apple brought back its once-exiled co-founder, Steve Jobs, as interim CEO and turned to its archrival Microsoft for a $150 million cash infusion to help pay its bills.

Jobs eventually introduced popular products such as the iPod and iPhone that subsequently drove Apple’s rise. The stock has been surging this week as anticipation mounts for the next generation of iPhone, expected to be released in September.

Apple hit the $1 trillion mark when its shares reached an all-time high of $207.05 around midday in New York. The shares are up 22 percent so far this year.

Jobs’ vision, showmanship and sense of style propelled Apple’s comeback. But it might not have happened if he hadn’t evolved into a more mature leader after his exit from the company in 1985. His ignominious departure came after losing a power struggle with John Sculley, a former Pepsico executive who he recruited to become Apple’s CEO in 1983 — seven years after he and his geeky friend Steve Wozniak teamed up to start the company with the administrative help of Ronald Wayne.

Jobs remained mercurial when he returned to Apple, but he had also become more thoughtful and adept at spotting talent that would help him create a revolutionary innovation factory. One of his biggest coups came in 1998 when he lured a soft-spoken Southerner, Tim Cook, away from Compaq Computer at a time when Apple’s survival remained in doubt.

Cook’s hiring may have been one of the best things Jobs did for Apple. In addition, that is, to shepherding a decade-long succession of iconic products that transformed Apple from a technological boutique to a cultural phenomenon and moneymaking machine.