The former chancellor and the Foreign Secretary finished in the top two places after five rounds of voting by Tory MPs, with Penny Mordaunt eliminated from the race after a bitter contest in Westminster.
Mr Sunak, the frontrunner throughout the parliamentary leg of the contest, received 137 votes in the final round of voting.
Ms Truss won 113 votes, narrowly pushing Ms Mordaunt into third place on 105.
Mr Sunak and Ms Truss will now face a campaign to win the votes of Tory members, with the result of the contest announced on September 5.
The winner is expected to replace Boris Johnson as prime minister the following day.
Ms Mordaunt had been second in all previous rounds of voting, but a late surge by Ms Truss cost her a place on the ballot.
The Foreign Secretary gained 27 votes, Mr Sunak put on 19 while Ms Mordaunt could only gain an extra 13 supporters.
Bookmakers have made Ms Truss the favourite to win the contest in the country, but Mr Sunak said he was best placed to beat Labour’s Sir Keir Starmer at the next election.
“We need to restore trust, rebuild the economy and reunite our country,” the former chancellor said.
“I’m confident that we can do that and we’ve got a really positive message to take out to all our members now – crucially, who is the best person to beat Keir Starmer and the Labour Party at the next election?
“I believe I’m the only candidate who can do that.”
— Ready For Rishi (@RishiSunak) July 20, 2022
Speaking to broadcasters, he denied lending candidates votes to manipulate the results throughout the contest after allegations of a dirty tricks campaign.
“Absolutely not. As you can see from the results that have just been declared, this has been a really close contest,” Mr Sunak said.
The Tory party announced 12 locations across the UK where they will hold public hustings between the final two, with the first being in Leeds on July 28.
They will visit Cardiff, Perth, Northern Ireland, Manchester and Birmingham int he following weeks before the final hustings in London on August 31.
Ms Truss said: “I am excited to now take to the country to make the case to the Conservative Party about my bold new economic plan that will cut taxes, grow our economy and unleash the potential of everyone in our United Kingdom.
“As prime minister I would hit the ground running from day one, unite the Party and govern in line with Conservative values.”
First they will take part in a televised BBC debate on Monday, and they have also signed up to a Sky head-to-head on August 4.
Previous debates saw them fiercely clash with each other and some Tories fear the damage further public rows will cause to the party.
In a sign of things to come, Truss-backer Sir Iain Duncan Smith said it would have been a “dereliction of duty” for her to leave Mr Johnson’s Government, in a possible jibe at Mr Sunak, whose resignation helped secure his downfall.
Sir Iain, a former Tory leader, insisted Ms Truss was not the “continuity” candidate and said he has “no idea” whether she has Mr Johnson’s support.
“Liz Truss stayed in the Cabinet, she had a very important job, it was Foreign Secretary, we’ve got a war going on in Ukraine, and a serious crisis, it would’ve been a dereliction of duty for her to have abandoned it and then promptly decided to get rid of him,” Sir Iain told BBC Radio 4’s PM programme.
“The truth is she was straightforward and loyal on that, and I think that was the right way to be.”
Ms Mordaunt congratulated her two rivals as she conceded.
“Politics isn’t easy. It can be a divisive and difficult place,” she said.
“We must all now work together to unify our party and focus on the job that needs to be done.”
— Liz for Leader (@trussliz) July 20, 2022
In his final Prime Minister’s Questions appearance, Mr Johnson offered advice to his successor and what appeared to be a swipe at his former chancellor.
The Prime Minister has not publicly backed any of the candidates, but some of his closest allies have supported Ms Truss.
Mr Sunak has said further tax cuts could only be delivered when inflation is under control and the public finances allow it, but Ms Truss has pledged to “start cutting taxes from day one”.
Mr Johnson’s advice was to: “Cut taxes and deregulate wherever you can and make this the greatest place to live and invest, which it is.”
He added that the new prime minister should be prepared to ignore their chancellor: “I love the Treasury but remember that if we’d always listened to the Treasury we wouldn’t have built the M25 or the Channel Tunnel.”
Mr Sunak’s resignation helped trigger the revolt against Mr Johnson which ultimately led to him accepting he had to quit No 10.
The Prime Minister said his successor should “focus on the road ahead, but always remember to check the rear-view mirror”.